aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-04-05 22:40:12 -0400
committertimmywil <tim.willison@thisismedium.com>2011-04-05 22:40:12 -0400
commitd47c0ae4228a59fcf731f626d650bb55c4e34609 (patch)
treec5575f05ac462a1f93b3d00e4bb8b58c1e1765d9
parent94fff6ff625be9fbbb54db53d9acec63f0919370 (diff)
downloadjquery-d47c0ae4228a59fcf731f626d650bb55c4e34609.tar.gz
jquery-d47c0ae4228a59fcf731f626d650bb55c4e34609.zip
Performance testing: localize val to each block and only set val to value when not a function
-rw-r--r--src/attributes.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/attributes.js b/src/attributes.js
index c8106e986..9fdb1492d 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -153,15 +153,15 @@ jQuery.fn.extend({
},
val: function( value ) {
- var hooks, val,
+ var hooks, ret,
elem = this[0];
if ( !arguments.length ) {
if ( elem ) {
hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];
- if ( hooks && "get" in hooks && (val = hooks.get( elem )) !== undefined ) {
- return val;
+ if ( hooks && "get" in hooks && (ret = hooks.get( elem )) !== undefined ) {
+ return ret;
}
return (elem.value || "").replace(rreturn, "");
@@ -173,15 +173,16 @@ jQuery.fn.extend({
var isFunction = jQuery.isFunction( value );
return this.each(function( i ) {
- var self = jQuery(this);
+ var self = jQuery(this), val;
if ( this.nodeType !== 1 ) {
return;
}
- val = value;
if ( isFunction ) {
val = value.call( this, i, self.val() );
+ } else {
+ val = value;
}
// Treat null/undefined as ""; convert numbers to string