News for hackers. Stuff that matters.
Re:The Future of JavaScript by herge on Friday February 10, 2012 @02:01PM (#3577017)

    > (Caveat: Iteration over collections is not yet specified)
Is this a joke? Is not iterating over dictionaries and arrays javascript's most glaring weakness?

How hard would it be to agree on something like foreach, that, you know, actually works the way you think it should work.

Re:The Future of JavaScript by tikhonj on Friday February 10, 2012 @03:35PM (#3577358)
There is a foreach that works: .forEach(). And when you're not just iterating over an array but transforming it, you have map(), reduce() and filter().
Re:The Future of JavaScript by herge on Friday February 10, 2012 @04:08PM (#3577490)
Is it really too much to ask to have some syntactic sugar. Is

    for i,v in blah
, where i is an index of an array, or a key (not a property!) of a dictionary really too much to ask in 2012?

No wonder people are using coffeescript.

Re:The Future of JavaScript by jashkenas on Friday February 10, 2012 @05:23PM (#3577738)
CoffeeScript's got you covered. Here's forEach ...

    for item, index in list
... here's the same over an object ...

    for key, value of object
... here's the map() ...

    mapped = for item in list
... here's the filter() ...

    filtered = for item in list when item.isActive
... and so on.
Re:The Future of JavaScript by herge on Friday February 10, 2012 @07:58PM (#3578191)
Exactly. The number one thing javascript should take from coffeescript is the iteration syntax.
Re:The Future of JavaScript by cmf028 on Saturday February 11, 2012 @01:21AM (#3578722)
ecmascript 6 will also introduce for of loops which is said to fix for in. checkout wiki.ecmascript.org for all the ecmascript 6/harmony niceness
Re:The Future of JavaScript by JoshTriplett on Friday February 10, 2012 @02:10PM (#3577054)
Remember that the spec won't come out for a while, after a pile of additional development. Also remember that we have to live with it for a long time, so taking the time to get it right seems preferable.
Re:The Future of JavaScript by samth on Saturday February 11, 2012 @12:43PM (#3579657)
A different way to put it is: "the best way to iterate over collections is still being discussed, because we want to get it right".

Also, for `Map`, how do you think `foreach` should work? Should the function be called with (a) the key, (b) the value, (c) an array with both the key and the value, (d) the key and the value as separate arguments?

Similarly, in the statement:

    for(let x of some_map) { ... }
should `x` range over the keys, values, or key-value pairs of the map?
Re:The Future of JavaScript by stevejohnson on Friday February 10, 2012 @02:08PM (#3577044)
My guess would be bikeshedding.