Subclassing ES6 objects with ES5 syntax.

C. Scott Ananian ecmascript at cscott.net
Wed Apr 29 19:02:35 UTC 2015


```
  constructor(x) {
    super(x);
    Object.defineProperties(this, { then: { value: this.then }});
    Object.freeze(this);
    if (this.constructor==DefensivePromise && this.then ===
DefensivePromise.prototype.then) {
      goodPromises.add(this);
    }
  }
```
Getting closer, I hope!


> I also like the point implicit in your attack that I also need the
> invariant that
>
> DefensivePromise.resolve(anything).then(anycallback)
>
> should all callback at most once.
>

I believe this is already taken care of by the ES6 spec once you make it
into `NewPromiseCapability`.  At least I wrote tests for `es6-shim` once
upon a time purporting to show this.
  --scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150429/63cffe06/attachment.html>


More information about the es-discuss mailing list