Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In jQuery 1.3.1 this is implemented slightly differently to the current versions:</p> <p><strong>v1.4.4</strong></p> <pre><code>removeAttr: function( name, fn ) { return this.each(function(){ jQuery.attr( this, name, "" ); if ( this.nodeType === 1 ) { this.removeAttribute( name ); } }); }, </code></pre> <p><strong>v1.3.1</strong></p> <pre><code>jQuery.each({ removeAttr: function( name ) { jQuery.attr( this, name, "" ); if (this.nodeType == 1) this.removeAttribute( name ); } }, function(name, fn){ jQuery.fn[ name ] = function(){ return this.each( fn, arguments ); }; }); </code></pre> <p>The functionality is more or less the same, both use <code>.each()</code> in all cases to process the list. The definition of each has not changed fundamentally at all:</p> <pre><code>// args is for internal usage only each: function( object, callback, args ) { var name, i = 0, length = object.length, isObj = length === undefined || jQuery.isFunction(object); if ( args ) { if ( isObj ) { for ( name in object ) { if ( callback.apply( object[ name ], args ) === false ) { break; } } } else { for ( ; i &lt; length; ) { if ( callback.apply( object[ i++ ], args ) === false ) { break; } } } // A special, fast, case for the most common use of each } else { if ( isObj ) { for ( name in object ) { if ( callback.call( object[ name ], name, object[ name ] ) === false ) { break; } } } else { for ( var value = object[0]; i &lt; length &amp;&amp; callback.call( value, i, value ) !== false; value = object[++i] ) {} } } return object; }, </code></pre> <p>So just a loop using <code>.call()</code> a lot.</p> <p>I think the only explanation as to a speed increase with an <strong><em>additional</em></strong> outer <code>.each()</code> loop would be the data structure size being much reduced to a single element before being passed down through many layers of calls, which is probably creating local data copies at each level. Passing the whole list through to deal with creates that much more overhead perhaps, would need to profile the heap usage to tell.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload