News for hackers. Stuff that matters.
Re:CoffeeScript: The beautiful way to write JavaScript by jashkenas on Tuesday March 08, 2011 @03:27PM (#2302466)
We need to make a distinction because we want to have arrays be iterated over with:

    for (var i = 0, l = list.length; i < l; i++) { ... }
And objects iterated over with:

    for (var key in object) { ... }
Using a "for-in" loop over a JS array isn't acceptable, for performance and semantics reasons, and neither is sniffing at runtime to determine whether the object passed is an array, or an object.

Ideally, JavaScript would have supported a single iteration protocol for both arrays and objects from the get-go, but alas...

There are no comments on this comment yet.