Subclassing ES6 objects with ES5 syntax.

Mark S. Miller erights at google.com
Wed Apr 29 18:07:57 UTC 2015


Hi Scott, I think your approach is on the right track. How about the
following?

Anyone see a way to attack it?



const goodPromises = new WeakSet();
class DefensivePromise {
  constructor(x) {
    super(x);
    if (new.target === DefensivePromise) {
      Object.freeze(this);
      goodPromises.add(this);
    }
  }
  static resolve(x) {
    if (goodPromises.has(x)) {
      return x;  // should be equiv to super.resolve(x);
    }
    return new DefensivePromise(r => {r(x)});
  }
}


Note a few typos fixed and a few simplifications, all of which you should
double check. Thanks!


--
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150429/70a275d4/attachment-0001.html>


More information about the es-discuss mailing list