Default `this` value for static promise functions
Domenic Denicola
d at domenic.me
Tue Apr 7 17:50:05 UTC 2015
Or just throw:
return getError().then(r => { throw r; })
> -----Original Message-----
> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of
> Brendan Eich
> Sent: Tuesday, April 7, 2015 13:47
> To: a.d.bergi at web.de
> Cc: es-discuss at mozilla.org
> Subject: Re: Default `this` value for static promise functions
>
> a.d.bergi at web.de wrote:
> > Hi,
> > I've just got bitten by
> >
> > return getError().then(Promise.reject);
> >
> > where `reject` threw an error that its `this` value was not a Promise
> constructor.
> >
> > Would it help to make the `C` constructor (in Promise.resolve,
> Promise.reject, Promise.all, Promise.race algorithms) default to `Promise`
> when no `this` value is supplied (throw only if it's there, but not an object and
> constructor function)?
>
> No, because as you suggested:
>
> > Or is this considered to be too error-prone with Promise subclassing, where
> `.then(MyCustomPromise.reject)` would not work as expected (fail silently)?
>
> Probably the best solution is an arrow:
>
> return getError().then(r => Promise.reject(r));
>
>
> /be
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
More information about the es-discuss
mailing list