why es6 Set prototype has values method?

时间:2016-10-20 12:50:38

标签: javascript ecmascript-6

Set.prototype.values() describe that values exist for similarity with Map object. I understand what it say but I don't understand why this similarity is desired?

2 个答案:

答案 0 :(得分:1)

Since values of a Set are unique, they could be thought of as keys.

why this similarity is desired?

No idea why it would be desired. In my opinion, it would be better not to have this choice.

答案 1 :(得分:0)

Here's the quote from the docs:

The keys() method is an alias for this method (for similarity with Map objects); it behaves exactly the same and returns values of Set elements.

And it means that there's another method, Set.prototype.keys() which is an alias for this method (Set.prototype.values()) so that Set objects would be more similar to Map objects, which have both of these methods on their prototypes.