News for hackers. Stuff that matters.
Re:CoffeeScript: The beautiful way to write JavaScript by jashkenas on Tuesday March 08, 2011 @02:45PM (#2302299)
To explain the reason for the "in/of" distinction...

"for item in list" vs "for key, value of object" is an unfortunate necessary evil. It would be great to use the same keyword, "in", for both types of loop, but I'm afraid there's no way for us to know at compile time if "list" or "object" is really an array, or really an object.

Re:CoffeeScript: The beautiful way to write JavaScript by hermanthegerman on Tuesday March 08, 2011 @03:35PM (#2302498)
The fact that cs is doing this 'the right way', meaning safe for all environments, as you have explained below, is one of the reasons I like it.
Re:CoffeeScript: The beautiful way to write JavaScript by boucher on Tuesday March 08, 2011 @03:16PM (#2302424)
I'm curious, why do you need to make a distinction? Is there some other feature of CS that depends on it? Certainly 'for key, value of array' could be implemented with numerical keys. If using just 'for value of dict' is allowed that would also work fine.
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...