Kevin Smith (2015-04-29T18:40:01.000Z)
d at domenic.me (2015-05-11T16:45:44.152Z)
> ```js > 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)}); > } > } > ``` Basically you can't rely on new.target to mean what you think it means, in the face of Reflect.construct. Maybe this? ```js constructor(x) { super(x); // At this point you know that "this" is a Promise, but you don't // know if the prototype is set correctly, so: if (Object.getPrototypeOf(this) === DefensivePromise.prototype) gooPromises.add(Object.freeze(this)); } ```