diff --git a/src/Angular.js b/src/Angular.js index 7c424897f..f5ab043dc 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -219,8 +219,7 @@ function isArrayLike(obj) { // NodeList objects (with `item` method) and // other objects with suitable length characteristics are array-like - return isNumber(length) && - (length >= 0 && ((length - 1) in obj || obj instanceof Array) || typeof obj.item === 'function'); + return isNumber(length) && (length >= 0 && (length - 1) in obj || typeof obj.item === 'function'); } @@ -635,12 +634,14 @@ function isDate(value) { * @kind function * * @description - * Determines if a reference is an `Array`. Alias of Array.isArray. + * Determines if a reference is an `Array`. * * @param {*} value Reference to check. * @returns {boolean} True if `value` is an `Array`. */ -var isArray = Array.isArray; +function isArray(arr) { + return Array.isArray(arr) || arr instanceof Array; +} /** * @description diff --git a/test/AngularSpec.js b/test/AngularSpec.js index c10b92e01..ffe157de5 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1254,6 +1254,37 @@ describe('angular', function() { }); }); + describe('isArray', function() { + + it('should return true if passed an `Array`', function() { + expect(isArray([])).toBe(true); + }); + + it('should return true if passed an `Array` from a different window context', function() { + var iframe = document.createElement('iframe'); + document.body.appendChild(iframe); // No `contentWindow` if not attached to the DOM. + var arr = new iframe.contentWindow.Array(); + document.body.removeChild(iframe); // Clean up. + + expect(arr instanceof Array).toBe(false); + expect(isArray(arr)).toBe(true); + }); + + it('should return true if passed an object prototypically inherited from `Array`', function() { + function FooArray() {} + FooArray.prototype = []; + + expect(isArray(new FooArray())).toBe(true); + }); + + it('should return false if passed non-array objects', function() { + expect(isArray(document.body.childNodes)).toBe(false); + expect(isArray({length: 0})).toBe(false); + expect(isArray({length: 2, 0: 'one', 1: 'two'})).toBe(false); + }); + + }); + describe('isArrayLike', function() { it('should return false if passed a number', function() {