Skip to content
Permalink
Browse files

Performance testing: localize val to each block and only set val to v…

…alue when not a function
  • Loading branch information...
timmywil
timmywil committed Apr 6, 2011
1 parent 94fff6f commit d47c0ae4228a59fcf731f626d650bb55c4e34609
Showing with 6 additions and 5 deletions.
  1. +6 −5 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

0 comments on commit d47c0ae

Please sign in to comment.
You can’t perform that action at this time.