Day 2 meeting notes
brendan at mozilla.com
Fri Jul 30 14:56:55 PDT 2010
On Jul 30, 2010, at 2:47 PM, felix wrote:
> On 7/30/10 14:37, Brendan Eich wrote:
>> For Harmony, we do not propose to standardize |for each|. Instead, the iteration and array comprehensions proposals for Harmony (see the wiki) propose that programmers choose keys, values, items (properties), or other iteration protocols by saying what they mean more precisely on the right-hand side of 'in':
>> for (k in keys(o)) ...
>> for (v in values(o)) ...
>> for ([k, v] in properties(o)) ... // Python's "items"
>> This seems better in TC39 members' views than adding ambiguous 'each' as a contextual keyword.
> I'm wary of that because this looks to me confusing:
> a = keys(o);
> for (k in a) ...
The confusion here seems to be assuming that |a| is an Array instance. It's not. It is an iterator, so you'll get the keys (property names) found in o -- you won't get 0, 1, ... a.length-1.
To avoid this confusion you can add new syntax (|for each| or whatever, doesn't matter). I've argued in recent posts that it is better from a global and long-term point of view to reform for-in after Python, than to condemn it and grow the language with new and generally more verbose, yet similar, syntax.
> or is keys(o) special syntax that only works within a for() statement?
More information about the es-discuss