aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Tortorini <thomastortorini@gmail.com>2015-06-25 06:18:04 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2015-07-27 19:57:34 +0200
commitbf48c21d225c31f0f9b5441d95f73615ca3dcfdb (patch)
treecd02658ecd5a3419f388aae4ea984f5dc85caa8c /src
parentd24275372624bac897c4131fd1507a58c09a1483 (diff)
downloadjquery-bf48c21d225c31f0f9b5441d95f73615ca3dcfdb.tar.gz
jquery-bf48c21d225c31f0f9b5441d95f73615ca3dcfdb.zip
Core: .each/.map should accept an undefined/null value
Fixes gh-2267 Closes gh-2363
Diffstat (limited to 'src')
-rw-r--r--src/core.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/core.js b/src/core.js
index ba6eeceb8..e8024aaf1 100644
--- a/src/core.js
+++ b/src/core.js
@@ -268,11 +268,10 @@ jQuery.extend({
},
each: function( obj, callback ) {
- var i = 0,
- length = obj.length,
- isArray = isArraylike( obj );
+ var length, i = 0;
- if ( isArray ) {
+ if ( isArrayLike( obj ) ) {
+ length = obj.length;
for ( ; i < length; i++ ) {
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break;
@@ -301,7 +300,7 @@ jQuery.extend({
var ret = results || [];
if ( arr != null ) {
- if ( isArraylike( Object(arr) ) ) {
+ if ( isArrayLike( Object( arr ) ) ) {
jQuery.merge( ret,
typeof arr === "string" ?
[ arr ] : arr
@@ -355,14 +354,13 @@ jQuery.extend({
// arg is for internal usage only
map: function( elems, callback, arg ) {
- var value,
+ var length, value,
i = 0,
- length = elems.length,
- isArray = isArraylike( elems ),
ret = [];
// Go through the array, translating each of the items to their new values
- if ( isArray ) {
+ if ( isArrayLike( elems ) ) {
+ length = elems.length;
for ( ; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
@@ -441,13 +439,13 @@ function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
-function isArraylike( obj ) {
+function isArrayLike( obj ) {
// Support: iOS 8.2 (not reproducible in simulator)
// `in` check used to prevent JIT error (gh-2145)
// hasOwn isn't used here due to false negatives
// regarding Nodelist length in IE
- var length = "length" in obj && obj.length,
+ var length = !!obj && "length" in obj && obj.length,
type = jQuery.type( obj );
if ( type === "function" || jQuery.isWindow( obj ) ) {