This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +27
-5
lines changed
2 files changed +27
-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 @@ -1119,17 +1119,38 @@ describe('angular', function() {
1119
1119
} ) ;
1120
1120
1121
1121
it ( 'should return true if passed a nodelist' , function ( ) {
1122
- var nodes = document . body . childNodes ;
1123
- expect ( isArrayLike ( nodes ) ) . toBe ( true ) ;
1122
+ var nodes1 = document . body . childNodes ;
1123
+ expect ( isArrayLike ( nodes1 ) ) . toBe ( true ) ;
1124
+
1125
+ var nodes2 = document . getElementsByTagName ( 'nonExistingTagName' ) ;
1126
+ expect ( isArrayLike ( nodes2 ) ) . toBe ( true ) ;
1124
1127
} ) ;
1125
1128
1126
1129
it ( 'should return false for objects with `length` but no matching indexable items' , function ( ) {
1127
- var obj = {
1130
+ var obj1 = {
1128
1131
a : 'a' ,
1129
1132
b :'b' ,
1130
1133
length : 10
1131
1134
} ;
1132
- expect ( isArrayLike ( obj ) ) . toBe ( false ) ;
1135
+ expect ( isArrayLike ( obj1 ) ) . toBe ( false ) ;
1136
+
1137
+ var obj2 = {
1138
+ length : 0
1139
+ } ;
1140
+ expect ( isArrayLike ( obj2 ) ) . toBe ( false ) ;
1141
+ } ) ;
1142
+
1143
+ it ( 'should return true for empty instances of an Array subclass' , function ( ) {
1144
+ function ArrayLike ( ) { }
1145
+ ArrayLike . prototype = Array . prototype ;
1146
+
1147
+ var arrLike = new ArrayLike ( ) ;
1148
+ expect ( arrLike . length ) . toBe ( 0 ) ;
1149
+ expect ( isArrayLike ( arrLike ) ) . toBe ( true ) ;
1150
+
1151
+ arrLike . push ( 1 , 2 , 3 ) ;
1152
+ expect ( arrLike . length ) . toBe ( 3 ) ;
1153
+ expect ( isArrayLike ( arrLike ) ) . toBe ( true ) ;
1133
1154
} ) ;
1134
1155
} ) ;
1135
1156
You can’t perform that action at this time.
0 commit comments