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

Brandon Benvie brandon at brandonbenvie.com
Thu Jan 10 08:48:48 PST 2013

At the very least, WeakMaps are potentially usable today (depending on the
target audience) while symbols are nowhere in sight. I’ve gotten a lot of
mileage out of this function, which as you said provides a similar
effective result as symbols (they differ in that the WeakMap version isn’t

    function createStorage(creator){
      var store = new WeakMap;
      creator || (creator = Object.create.bind(null, null, {}));

      return function(obj){
        var priv = store.get(obj);
        if (!priv) store.set(obj, priv = creator(obj));
        return o;

    // usage
    var _ = createStorage();

    function Ctor(val){
      _(this).private = val;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130110/90d19677/attachment-0001.html>

More information about the es-discuss mailing list