@@ -191,57 +191,31 @@ var
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
+
194
199
/**
195
200
* @private
196
201
* @param {* } obj
197
202
* @return {boolean } Returns true if `obj` is an array or array-like object (NodeList, Arguments,
198
203
* String ...)
199
204
*/
200
205
function isArrayLike ( obj ) {
201
- // snake case is to avoid shadowing camel-cased globals
202
- var length , objExists , isNodeList , isArguments , isSomeOtherObj , is_array , is_string , is_object ;
203
- objExists = isDefined ( obj ) && obj !== null ;
206
+
207
+ // `null`, `undefined` and `window` are not array-like
208
+ if ( obj == null || isWindow ( obj ) ) return false ;
209
+
210
+ // arrays and strings are array like
211
+ if ( isArray ( obj ) || isString ( obj ) ) return true ;
212
+
204
213
// Support: iOS 8.2 (not reproducible in simulator)
205
214
// "length" in obj used to prevent JIT error (gh-11508)
206
- length = objExists ? "length" in Object ( obj ) && obj . length : false ;
207
- is_array = isArray ( obj ) ;
208
- is_string = isString ( obj ) ;
209
- is_object = isObject ( obj ) ;
210
- isNodeList = objExists && obj . nodeType === 1 && length ;
211
- isArguments = objExists &&
212
- ( Object . prototype . toString . call ( obj ) === '[object Arguments]' ||
213
- ( Object . prototype . hasOwnProperty . call ( obj , 'length' ) &&
214
- Object . prototype . hasOwnProperty . call ( obj , 'callee' ) ) ) ;
215
-
216
- // this only works if it doesn't return 'object' from typeof and isn't another arrayLike
217
- isSomeOtherObj = objExists &&
218
- ! isNodeList &&
219
- ! is_array &&
220
- ! is_string &&
221
- ! isArguments &&
222
- (
223
- ( ! is_object &&
224
- length === 0 ) ||
225
- (
226
- isNumber ( length ) &&
227
- length >= 0 &&
228
- ( length - 1 ) in obj
229
- )
230
- ) ;
215
+ var length = "length" in Object ( obj ) && obj . length ;
231
216
232
- return (
233
- objExists &&
234
- ! isWindow ( obj ) &&
235
- (
236
- (
237
- isNodeList ||
238
- is_string ||
239
- is_array ||
240
- isArguments
241
- ) ||
242
- isSomeOtherObj
243
- )
244
- ) ;
217
+ // node lists and objects with suitable length characteristics are array-like
218
+ return ( isNumber ( length ) && length >= 0 && ( length - 1 ) in obj ) || isNodeList ( obj ) ;
245
219
}
246
220
247
221
/**
@@ -501,7 +475,7 @@ identity.$inject = [];
501
475
function valueFn ( value ) { return function ( ) { return value ; } ; }
502
476
503
477
function hasCustomToString ( obj ) {
504
- return isFunction ( obj . toString ) && obj . toString !== Object . prototype . toString ;
478
+ return isFunction ( obj . toString ) && obj . toString !== toString ;
505
479
}
506
480
507
481
0 commit comments