const {resolve} = Promise; // fails

T.J. Crowder tj.crowder at farsightsoftware.com
Thu Jul 19 14:10:46 UTC 2018


On Thu, Jul 19, 2018 at 12:56 PM, Andrea Giammarchi
<andrea.giammarchi at gmail.com> wrote:
> Why cannot Promise methods fallback to Promise constructor when the
> class/context is not available?

That sounds reasonable on first glance, but I'd be concerned about what
happens when you do it after subclassing:

```js
class MyPromise extends Promise {
    // ...and adds some important feature...
}
// ...
const {resolve, reject} = MyPromise;
const p = resolve();
p.someImportantFeature(/*...*/); // TypeError: undefined is not a function
```

...since `resolve` fell back to `Promise`. That feels like a footgun.
Either subclassers would have to handle that, which they will forget to do,
or it has to be a bit more complicated than just a simple fallback to `
Promise` (I don't immediately know what that "more complicated" answer
would be.)

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180719/5620d597/attachment.html>


More information about the es-discuss mailing list