Exception handling vs. hasNext()

Brendan Eich brendan at mozilla.org
Mon Nov 19 11:22:28 PST 2007


On Nov 19, 2007, at 6:45 PM, P T Withington wrote:

> On 2007-11-19, at 12:40 EST, Brendan Eich wrote:
>
>> This item iteration case has no more concise form analogous to for-
>> each-in, because if ES4 were always to map:
>>
>> for (let [k, v] in map) ...
>>
>> to:
>>
>> for (let [k, v] in map.iterator::getItems()) ...
>>
>> it would wrongly preempt destructuring of arbitrary properties from
>> the value returned by the default iterator
>
> Say, if we don't waste parens on union types, what's wrong with:
>
> for (let (k, v) in map) ...

Union types are irrelevant in value expressions anyway, but group  
assignment was rejected in favor of destructuring (based on Opera  
precedent). See

http://wiki.ecmascript.org/doku.php?id=proposals:group_assignment

Consider that the implementation of a "group" or "tuple" iterator  
will return [k, v] or [s, v, o]. The array destructuring syntax  
mimicks array initialiser syntax. Same goes for object destructuring,  
with a convenient shorthand:

   let {p: a, q: b} = o   // bind a = o.p and b = o.q

When you want the bound names to be the same as the destructured  
property names, use the shorthand:

   let {p, q} = o

Since we're not adding tuples as a distinct type expressed using  
parentheses, the let [k, v] form remains.

/be




More information about the Es4-discuss mailing list