Set.prototype.forEach
which accepts a callback function in ES6 The function has 3 parameters to be consistent with Map.prototype.forEach
. MDN says both the first 2 parameters for the callback are values because there is no keys in Set
object. Why the item in Set
is considered as value instead of key? No duplicated key in Set
object would make more sense because there is also no duplicated key in Map
.
Another aspect that value in Set
looks like key in Map
is that it makes Set.prototype.has(value)
and Map.prototype.has(key)
more consistent. Duplicated keys are NOT allowed in Array
(key is index) and Map
, but this cannot be extended to Set
which doesn't allow duplicated values. Make it as duplicated keys are not allowed in all containers might be a more succinct rule.