Augusto Moura (2018-07-20T20:29:55.000Z)
You are right, I didn't know you can use variables before calling the super
constructor (a Java thing).
So yeah, it's pretty easy to extend a Promise to externalize resolve and
reject

---
PS: Sorry about my last email last paragraph grammar, I'm yet getting used
to write long texts in English

Em sex, 20 de jul de 2018 às 15:57, Richard Gibson <richard.gibson at gmail.com>
escreveu:

> On Fri, Jul 20, 2018 at 12:15 PM Augusto Moura <augusto.borgesm at gmail.com>
> wrote:
>
>> Interesting enough, I got a really weird case (reads contraintuitive, I'm
>> pretty sure the semantics of the error are right) extending the Promise
>> class to exemplify a simple Deferred implementation, the code:
>>
>> ``` js
>> class Deferred extends Promise {
>>   constructor(factory) {
>>     super((resolve, reject) => {
>>       Object.assign(this, { reject, resolve });
>>       factory(resolve, reject);
>>     });
>>   }
>> }
>>
>> const d = new Deferred(() => {});
>> ```
>> The problem is the usage of `this` before calling the super constructor
>> (even when the using in the super call itself).
>>
>
> Isn't the solution the pattern we've already seen?
> ```js
> class Deferred extends Promise {
>   constructor(factory) {
>     const methods = {};
>     super((resolve, reject) => Object.assign(methods, { resolve, reject })
> );
>     Object.assign(this, methods);
>     factory(this.resolve, this.reject);
>   }
> }
> ```
>
-- 
Augusto Moura
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180720/cdf4a25d/attachment-0001.html>
augusto.borgesm at gmail.com (2018-07-20T20:31:02.155Z)
You are right, I didn't know you can use variables before calling the super
constructor (a Java thing).
So yeah, it's pretty easy to extend a Promise to externalize resolve and
reject

---
PS: Sorry about my last email last paragraph grammar, I'm yet getting used
to write long texts in English