Skip to content
Permalink
Browse files
Just pushed in my changes for making jQuery.each on objects faster, s…
  • Loading branch information
jeresig committed Aug 20, 2007
1 parent f0353e8 commit 05fb8eaa1058578f911ab5d0d4436e97010f4cc7
Showing 1 changed file with 15 additions and 9 deletions.
@@ -1391,17 +1391,23 @@ jQuery.extend({
*/
// args is for internal usage only
each: function( obj, fn, args ) {
if ( obj.length == undefined )
for ( var i in obj )
fn.apply( obj[i], args || [i, obj[i]] );
else if ( args ) {
for ( var i = 0, ol = obj.length; i < ol; i++ )
if ( fn.apply( obj[i], args ) === false ) break;
if ( args ) {
if ( obj.length == undefined )
for ( var i in obj )
fn.apply( obj[i], args );
else
for ( var i = 0, ol = obj.length; i < ol; i++ )
if ( fn.apply( obj[i], args ) === false ) break;

// A special, fast, case for the most common use of each
} else
for ( var i = 0, ol = obj.length, val = obj[0];
i < ol && fn.call(val,i,val) !== false; val = obj[++i] );
} else {
if ( obj.length == undefined )
for ( var i in obj )
fn.call( obj[i], i, obj[i] );
else
for ( var i = 0, ol = obj.length, val = obj[0];
i < ol && fn.call(val,i,val) !== false; val = obj[++i] );
}

return obj;
},

0 comments on commit 05fb8ea

Please sign in to comment.