Set.prototype.entries: indices as keys?

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Mon Jan 19 16:57:47 PST 2015


On Monday, January 19, 2015, Brendan Eich <brendan at mozilla.org> wrote:

> Dmitry Soshnikov wrote:
>
>>
>>     ```js
>>     let [x,y] = set; // x='a'; y='b’;
>>     ```
>>
>>
>> Would this work actually? :) Destructuring does get property, which
>> wouldn't call set's `get` method.
>>
>
> See http://people.mozilla.org/~jorendorff/es6-draft.html#sec-
> runtime-semantics-destructuringassignmentevaluation -- destructuring
> array patterns uses the iteration protocol, which is why the line works as
> Axel suggested:
>
>
Ah, I see, that's great! Thanks for clarification.

Dmitry


> js> let set = new Set(['a', 'b']);
> js> let [x,y] = set;
> js> console.log(x, y)
> a b
> js> for (let elt of set) console.log(elt)
> a
> b
>
> But not all iterables are indexable, nor should they be.
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150119/c9bf3c71/attachment.html>


More information about the es-discuss mailing list