Skip to content

Commit

Permalink
Core: change jQuery.each and jQuery#each signatures
Browse files Browse the repository at this point in the history
Fixes gh-2090
Closes gh-2097
  • Loading branch information
markelog committed Feb 19, 2015
1 parent a4715f4 commit 2380028
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions src/core.js
Expand Up @@ -74,10 +74,8 @@ jQuery.fn = jQuery.prototype = {
}, },


// Execute a callback for every element in the matched set. // Execute a callback for every element in the matched set.
// (You can seed the arguments with an array of args, but this is each: function( callback ) {
// only used internally.) return jQuery.each( this, callback );
each: function( callback, args ) {
return jQuery.each( this, callback, args );
}, },


map: function( callback ) { map: function( callback ) {
Expand Down Expand Up @@ -269,40 +267,21 @@ jQuery.extend({
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
}, },


// args is for internal usage only each: function( obj, callback ) {
each: function( obj, callback, args ) {
var i = 0, var i = 0,
length = obj.length, length = obj.length,
isArray = isArraylike( obj ); isArray = isArraylike( obj );


if ( args ) { if ( isArray ) {
if ( isArray ) { for ( ; i < length; i++ ) {
for ( ; i < length; i++ ) { if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
if ( callback.apply( obj[ i ], args ) === false ) { break;
break;
}
}
} else {
for ( i in obj ) {
if ( callback.apply( obj[ i ], args ) === false ) {
break;
}
} }
} }

// A special, fast, case for the most common use of each
} else { } else {
if ( isArray ) { for ( i in obj ) {
for ( ; i < length; i++ ) { if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { break;
break;
}
}
} else {
for ( i in obj ) {
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break;
}
} }
} }
} }
Expand Down

2 comments on commit 2380028

@Krinkle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read the commit subject in the log, I thought this was going to be a major breaking change rewriting each() to be more like map() 😟 (or something like that).

May wanna use a commit message more descriptive than "Change (something)", e.g. "Remove internal args argument" :)

@lvlvforever
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the document on the internet mostly say we could attach more parameters on $.each(),it took me some time to find that my jquery version is 1.12.4。Eventually i find this page and read the source 1.12.4 and 1.11.2 .
src is a good thing,maybe the best of the world ^_^

Please sign in to comment.