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
inherited):


    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;
    }
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to