Promise.resolve

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Promise.resolve

Sultan
Was there any reason Promise.resolve was not afforded the ability to dispatch outside of `this` pointing to the `Promise` constructor?

For example:

const {resolve} = Promise
resolve(1234)

This currently throws.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Promise.resolve

Logan Smyth
`Promise` can be subclassed, so the `this` context for `resolve` affects what class is instantiated.

On Sat, Feb 2, 2019 at 12:25 PM Sultan <[hidden email]> wrote:
Was there any reason Promise.resolve was not afforded the ability to dispatch outside of `this` pointing to the `Promise` constructor?

For example:

const {resolve} = Promise
resolve(1234)

This currently throws.
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Promise.resolve

Michał Wadas
This is not valid answer. Arrays can be subclassed too, but (1,Array.of)(2,3) returns instance of Array.

On Sat, Feb 2, 2019 at 10:20 PM Logan Smyth <[hidden email]> wrote:
`Promise` can be subclassed, so the `this` context for `resolve` affects what class is instantiated.

On Sat, Feb 2, 2019 at 12:25 PM Sultan <[hidden email]> wrote:
Was there any reason Promise.resolve was not afforded the ability to dispatch outside of `this` pointing to the `Promise` constructor?

For example:

const {resolve} = Promise
resolve(1234)

This currently throws.
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Promise.resolve

Augusto Moura
It is the valid answer, subclassing is the reason behind the design choice of Promise static members depending on `this`. If it was a good decision or not is another topic. `Array.of` was designed in a different occasion and static methods inheritance was not a subject at the time

Em dom, 3 de fev de 2019 22:04, Michał Wadas <[hidden email] escreveu:
This is not valid answer. Arrays can be subclassed too, but (1,Array.of)(2,3) returns instance of Array.

On Sat, Feb 2, 2019 at 10:20 PM Logan Smyth <[hidden email]> wrote:
`Promise` can be subclassed, so the `this` context for `resolve` affects what class is instantiated.

On Sat, Feb 2, 2019 at 12:25 PM Sultan <[hidden email]> wrote:
Was there any reason Promise.resolve was not afforded the ability to dispatch outside of `this` pointing to the `Promise` constructor?

For example:

const {resolve} = Promise
resolve(1234)

This currently throws.
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Promise.resolve

medikoo
You'll find a solid explanantion here:
https://github.com/tc39/ecma262/issues/544#issuecomment-275881668

Array.from, Array.of were designed in very early stage of ES2015, and fact
that they work that way (while e.g. Promise.resolve does not), is now
considered a mistake that was too late to revert at some point.



--
Sent from: http://mozilla.6506.n7.nabble.com/Mozilla-ECMAScript-4-discussion-f89340.html
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss