jashkenas/underscore

_.each fails on objects with a length property

codepunkt opened this issue · 1 comments

because of this check

obj.length === +obj.length

objects with a length property get treated as an array.

// logs nothing
_.each({ one: 1, two: 2, length: 3 }, function(num) { console.log(num); });

is this the desired behavior? even though this should be faster than {}.toString.call(obj) === '[object Array]', this doesn't seem right.

seems this has been discussed before.
sorry for the inconvenience ;)