Permalink
Browse files

Core: change jQuery.each and jQuery#each signatures

Fixes gh-2090
Closes gh-2097
  • Loading branch information...
markelog committed Feb 17, 2015
1 parent a4715f4 commit 2380028ec4a6a77401b867a51de26a3cb8e8d311
Showing with 10 additions and 31 deletions.
  1. +10 −31 src/core.js
View
@@ -74,10 +74,8 @@ jQuery.fn = jQuery.prototype = {
},
// Execute a callback for every element in the matched set.
- // (You can seed the arguments with an array of args, but this is
- // only used internally.)
- each: function( callback, args ) {
- return jQuery.each( this, callback, args );
+ each: function( callback ) {
+ return jQuery.each( this, callback );
},
map: function( callback ) {
@@ -269,40 +267,21 @@ jQuery.extend({
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
},
- // args is for internal usage only
- each: function( obj, callback, args ) {
+ each: function( obj, callback ) {
var i = 0,
length = obj.length,
isArray = isArraylike( obj );
- if ( args ) {
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- if ( callback.apply( obj[ i ], args ) === false ) {
- break;
- }
- }
- } else {
- for ( i in obj ) {
- if ( callback.apply( obj[ i ], args ) === false ) {
- break;
- }
+ if ( isArray ) {
+ for ( ; i < length; i++ ) {
+ if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
+ break;
}
}
-
- // A special, fast, case for the most common use of each
} else {
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
- break;
- }
- }
- } else {
- for ( i in obj ) {
- if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
- break;
- }
+ for ( i in obj ) {
+ if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
+ break;
}
}
}

2 comments on commit 2380028

@Krinkle

This comment has been minimized.

Show comment
Hide comment
@Krinkle

Krinkle Feb 21, 2015

Member

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" :)

Member

Krinkle replied Feb 21, 2015

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

This comment has been minimized.

Show comment
Hide comment
@lvlvforever

lvlvforever Jul 19, 2017

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 ^_^

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.