This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,8 @@ function isArrayLike(obj) {
215
215
// NodeList objects (with `item` method) and
216
216
// other objects with suitable length characteristics are array-like
217
217
return isNumber ( length ) &&
218
- ( length >= 0 && ( length - 1 ) in obj || typeof obj . item == 'function' ) ;
218
+ ( length >= 0 && ( ( length - 1 ) in obj || obj instanceof Array ) || typeof obj . item == 'function' ) ;
219
+
219
220
}
220
221
221
222
/**
Original file line number Diff line number Diff line change @@ -1218,17 +1218,34 @@ describe('angular', function() {
1218
1218
} ) ;
1219
1219
1220
1220
it ( 'should return true if passed a nodelist' , function ( ) {
1221
- var nodes = document . body . childNodes ;
1222
- expect ( isArrayLike ( nodes ) ) . toBe ( true ) ;
1221
+ var nodes1 = document . body . childNodes ;
1222
+ expect ( isArrayLike ( nodes1 ) ) . toBe ( true ) ;
1223
+
1224
+ var nodes2 = document . getElementsByTagName ( 'nonExistingTagName' ) ;
1225
+ expect ( isArrayLike ( nodes2 ) ) . toBe ( true ) ;
1223
1226
} ) ;
1224
1227
1225
1228
it ( 'should return false for objects with `length` but no matching indexable items' , function ( ) {
1226
- var obj = {
1229
+ var obj1 = {
1227
1230
a : 'a' ,
1228
1231
b :'b' ,
1229
1232
length : 10
1230
1233
} ;
1231
- expect ( isArrayLike ( obj ) ) . toBe ( false ) ;
1234
+ expect ( isArrayLike ( obj1 ) ) . toBe ( false ) ;
1235
+
1236
+ var obj2 = {
1237
+ length : 0
1238
+ } ;
1239
+ expect ( isArrayLike ( obj2 ) ) . toBe ( false ) ;
1240
+ } ) ;
1241
+
1242
+ it ( 'should return true for empty instances of an Array subclass' , function ( ) {
1243
+ function ArrayLike ( ) { }
1244
+ ArrayLike . prototype = Array . prototype ;
1245
+
1246
+ var arrLike = new ArrayLike ( ) ;
1247
+
1248
+ expect ( isArrayLike ( arrLike ) ) . toBe ( true ) ;
1232
1249
} ) ;
1233
1250
} ) ;
1234
1251
You can’t perform that action at this time.
0 commit comments