Set.prototype.entries: indices as keys?
Brendan Eich
brendan at mozilla.org
Mon Jan 19 11:19:11 PST 2015
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:
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
More information about the es-discuss
mailing list