On Sun, Jan 18, 2015 at 4:28 AM, Axel Rauschmayer <[email protected]> wrote:

> Currently the keys of the entries returned by `Set.prototype.entries()`
> are the same as the values:
>
> ```js
> let set = new Set(['a', 'b']);
>
> let pairs = [...set.entries()];
> console.log(JSON.stringify(pairs)); // [["a","a"],["b","b”]]
> ```
>

To begin with: `.entries()` doesn't make much sense in Sets abstraction at
all (as well as `.keys()`). But the ship was sailed.

Sets are just a sugar on top of maps in ES6 (with just renamed API methods).


>
> Given that sets are ordered, I’d use the “position” of an entry as the
> key: [[0,"a"],[1,"b”]]
>

This notation would assume that a set may have non-unique values (e.g. "a"
at index 0, and "a" at index 2), and in this case it wouldn't be a set
anymore.


>
> Rationale: First, having an indices as keys makes the entries more useful.
> Second, destructuring already treats entries as if they had indices:
>
> ```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.

Dmitry
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to