Promise sub-class: super((resolve, reject) => this) ?

Sebastian McKenzie sebmck at gmail.com
Tue Jun 2 22:49:33 UTC 2015


Ah, completely right. At first glance I thought it was this similar but separate issue:



```js


class Foo {

  constructor(callback) {

    this.callback = callback; // just storing it!

  }

}




class Bar extends Foo {

  constructor() {

    super(() => this); // reference to `this` will throw since the behaviour of the super class can’t be easily inferred

  }

}



```




Shifting runtime errors to compile time isn’t always the most reliable.

On Tue, Jun 2, 2015 at 11:43 PM, Domenic Denicola <d at domenic.me> wrote:

> Hmm I am pretty sure Babel et al. are correct here in not allowing this. The super call needs to *finish* before you can use `this`. Chrome also works this way.
> The correct workaround is
> ```js
> let resolve, reject;
> super((a, b) => {
>   resolve = a;
>   reject = b;
> });
> // use this
> ```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150602/206b3aaa/attachment.html>


More information about the es-discuss mailing list