WeakMap better than Private Symbols? (was: direct_proxies "problem")

Brendan Eich brendan at mozilla.com
Thu Jan 10 09:00:48 PST 2013

Symbols (private or public, don't forget the latter) are crucial to ES6 
and not going away :-|.

Besides the property access and GC costs of WeakMaps (which are probably 
fine, but at least inevitable, when you really do need a WeakMap), 
symbols allow coordination between friendly objects by name, without 
exposing a map full of names, plural.

Finally, symbols allow property access to be abstracted functionally:

   function get(obj, key) { return obj[key]; }
   function set(obj, key, val) { obj[key] = val; }

No such abstraction with weakmaps.

Different tools in your belt are a good thing. We don't fault the 
screwdriver for being a poor hammer, or vice versa!


Kevin Smith wrote:
>     They both have their place since there's many uses for both
>     inherited and non-inherited private values.
> Can we see some demonstrated use-cases for which WeakMaps are 
> insufficient, and private properties are?  I continue to hear that 
> private symbols are a great idea without any discussion of the 
> tradeoff:  a more complicated (and more difficult to reason about) 
> runtime object model.
> { Kevin }
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

More information about the es-discuss mailing list