Default value argument for Map/WeakMap.prototype.get()
jason.orendorff at gmail.com
Wed Nov 28 11:07:56 PST 2012
I propose adding an optional second argument to the .get() method on Map
The default value would be returned only when the given key is not in the
map. That is, in the last step of the spec for these two methods, instead
of "Return undefined", it would say "Return defaultValue".
Python and Ruby have this. (In Ruby it's called "fetch".) It's handy in
var counts = new Map;
for (let word of words)
counts.set(word, counts.get(word, 0) + 1);
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss