A different semantics for WeakMap#get default value

Axel Rauschmayer axel at rauschma.de
Mon Jan 16 14:25:10 PST 2012

I’m not sure how much this is needed for WeakMaps in particular, but when you nest data structures then it’s handy to automatically create an entry if it is missing. I’ve seen  collection frameworks where maps have an optional constructor argument: a function that auto-creates an entry if it is missing.

But we are entering complex API territory and those decisions might best be delegated to whoever creates a collections library for JavaScript.

On Jan 16, 2012, at 22:46 , Mark S. Miller wrote:

> David and Axel, I don't get it. What's wrong with the get with the optional default value, as specified by that text and as currently implemented by FF? What additional value does this contingent mutation add, regardless of how it's packaged? Do you really want "has" to answer true for a key merely because a previous get (or setdefault) with that key caused a default value to be stored? Axel, does this add enough value to expand the API by 25%?

Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120116/60765483/attachment.html>

More information about the es-discuss mailing list