Skip to content

Commit

Permalink
fix(isArrayLike): correctly handle string primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
mernen committed Aug 23, 2013
1 parent 699f86c commit 79c7b92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ function isArrayLike(obj) {
return true;
}

return isArray(obj) || !isFunction(obj) && (
length === 0 || typeof length === "number" && length > 0 && (length - 1) in obj
);
if (typeof obj !== 'object') {

This comment has been minimized.

Copy link
@btford

btford Oct 2, 2013

It's better to just use isString here. I'm going to make this change before merging this commit.

return typeof obj === 'string';
}

return isArray(obj) || length === 0 ||
typeof length === "number" && length > 0 && (length - 1) in obj;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@ describe('angular', function() {
expect(log).toEqual(['0:a', '1:b', '2:c']);
});

it('should handle string values like arrays', function() {
var log = [];

forEach('bar', function(value, key) { log.push(key + ':' + value)});
expect(log).toEqual(['0:b', '1:a', '2:r']);
});


it('should handle objects with length property as objects', function() {
var obj = {
Expand Down

0 comments on commit 79c7b92

Please sign in to comment.