_.each fails with objects with a length key #252

Closed
jeffv opened this Issue Jul 19, 2011 · 2 comments

Comments

Projects
None yet
3 participants

jeffv commented Jul 19, 2011

var _ = require('underscore');

banana = {
length: 999
}

_.each(banana, function(val) {
console.log('Got Here'); //fails
})

If banana.length is a string, rather then an integer, it suddenly works. When I did I search I saw a long discussion on this subject back in march. Any head way made? This really surprised me when I came across it. There's nothing in the documentation saying this is a failure case when foreaching over an object.

I have a situation where I can't rename the key so I've had to ditch underscore temporarily.

Collaborator

michaelficarra commented Jul 19, 2011

See 5eaf71f, 942d6312, and 727db393 for the recent change that affected this. Still, an object with a numeric length value was treated as an array by _.each before then. That was decided long before those commits, and it's a decision I support.

Owner

jashkenas commented Aug 3, 2011

This is a dup of #154 and #148 ... I've added a paragraph about it to the documentation -- see the above commit.

@jashkenas jashkenas closed this Aug 3, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment