191
191
msie = document . documentMode ;
192
192
193
193
194
- function isNodeList ( obj ) {
195
- return typeof obj . length == 'number' &&
196
- typeof obj . item == 'function' ;
197
- }
198
-
199
194
/**
200
195
* @private
201
196
* @param {* } obj
@@ -207,15 +202,20 @@ function isArrayLike(obj) {
207
202
// `null`, `undefined` and `window` are not array-like
208
203
if ( obj == null || isWindow ( obj ) ) return false ;
209
204
210
- // arrays and strings are array like
211
- if ( isArray ( obj ) || isString ( obj ) ) return true ;
205
+ // arrays, strings and jQuery/jqLite objects are array like
206
+ // * jqLite is either the jQuery or jqLite constructor function
207
+ // * we have to check the existance of jqLite first as this method is called
208
+ // via the forEach method when constructing the jqLite object in the first place
209
+ if ( isArray ( obj ) || isString ( obj ) || ( jqLite && obj instanceof jqLite ) ) return true ;
212
210
213
211
// Support: iOS 8.2 (not reproducible in simulator)
214
212
// "length" in obj used to prevent JIT error (gh-11508)
215
213
var length = "length" in Object ( obj ) && obj . length ;
216
214
217
- // node lists and objects with suitable length characteristics are array-like
218
- return ( isNumber ( length ) && length >= 0 && ( length - 1 ) in obj ) || isNodeList ( obj ) ;
215
+ // NodeList objects (with `item` method) and
216
+ // other objects with suitable length characteristics are array-like
217
+ return isNumber ( length ) &&
218
+ ( length >= 0 && ( length - 1 ) in obj || typeof obj . item == 'function' ) ;
219
219
}
220
220
221
221
/**
0 commit comments