Default `this` value for static promise functions
# Brendan Eich (10 years ago)
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 itsthis
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 toPromise
when nothis
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));
# Domenic Denicola (10 years ago)
Or just throw:
return getError().then(r => { throw r; })
I've just got bitten by
where
reject
threw an error that itsthis
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 toPromise
when nothis
value is supplied (throw only if it's there, but not an object and constructor function)? Or is this considered to be too error-prone with Promise subclassing, where.then(MyCustomPromise.reject)
would not work as expected (fail silently)?