This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +30
-10
lines changed
2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -80,19 +80,19 @@ var /** holds major version number for IE or NaN for real browsers */
80
80
* @return {boolean } Returns true if `obj` is an array or array-like object (NodeList, Arguments, ...)
81
81
*/
82
82
function isArrayLike ( obj ) {
83
- if ( ! obj || ( typeof obj . length !== 'number' ) ) return false ;
83
+ if ( obj == null || isWindow ( obj ) ) {
84
+ return false ;
85
+ }
86
+
87
+ var length = obj . length ;
84
88
85
- // We have on object which has length property. Should we treat it as array?
86
- if ( typeof obj . hasOwnProperty != 'function' &&
87
- typeof obj . constructor != 'function' ) {
88
- // This is here for IE8: it is a bogus object treat it as array;
89
+ if ( obj . nodeType === 1 && length ) {
89
90
return true ;
90
- } else {
91
- return obj instanceof JQLite || // JQLite
92
- ( jQuery && obj instanceof jQuery ) || // jQuery
93
- toString . call ( obj ) !== '[object Object]' || // some browser native object
94
- typeof obj . callee === 'function' ; // arguments (on IE8 looks like regular obj)
95
91
}
92
+
93
+ return isArray ( obj ) || ! isFunction ( obj ) && (
94
+ length === 0 || typeof length === "number" && length > 0 && ( length - 1 ) in obj
95
+ ) ;
96
96
}
97
97
98
98
/**
Original file line number Diff line number Diff line change @@ -77,7 +77,27 @@ describe('ngRepeat', function() {
77
77
expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
78
78
expect ( element . text ( ) ) . toEqual ( 'x;y;x;' ) ;
79
79
} ) ;
80
+
81
+ it ( 'should iterate over an array-like class' , function ( ) {
82
+ function Collection ( ) { }
83
+ Collection . prototype = new Array ( ) ;
84
+ Collection . prototype . length = 0 ;
80
85
86
+ var collection = new Collection ( ) ;
87
+ collection . push ( { name : "x" } ) ;
88
+ collection . push ( { name : "y" } ) ;
89
+ collection . push ( { name : "z" } ) ;
90
+
91
+ element = $compile (
92
+ '<ul>' +
93
+ '<li ng-repeat="item in items">{{item.name}};</li>' +
94
+ '</ul>' ) ( scope ) ;
95
+
96
+ scope . items = collection ;
97
+ scope . $digest ( ) ;
98
+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
99
+ expect ( element . text ( ) ) . toEqual ( 'x;y;z;' ) ;
100
+ } ) ;
81
101
82
102
it ( 'should iterate over on object/map' , function ( ) {
83
103
element = $compile (
You can’t perform that action at this time.
0 commit comments