const {resolve} = Promise; // fails
Andrea Giammarchi
andrea.giammarchi at gmail.com
Thu Jul 19 23:22:20 UTC 2018
Reading that looks like nobody answered my question, explained through some
code that wouldn't have any issue with subclassing.
So no, there's no answer to my latest question in there, unless I've missed
it.
On Thu, Jul 19, 2018 at 7:56 PM Jordan Harband <ljharb at gmail.com> wrote:
> This question has been answered here:
> https://github.com/tc39/ecma262/issues/544
>
> On Thu, Jul 19, 2018 at 9:27 AM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
>> > Per the KISS principle, let’s avoid to be clever.
>>
>> I think my next code example is less clever, but the only reason I've
>> written hacks or code was not to be advocated or adopted, just to explain
>> what could happen internally.
>>
>> TL;DR why aren't public static methods that need context **all** lazily
>> defined as bound (once) on demand? That would make every single public
>> static method consistent, accordingly with the Class you extracted them
>> from, right? That's not clever, that's usually developers expectations
>> because historically all public static methods don't need the Class to work.
>>
>> On Thu, Jul 19, 2018 at 5:23 PM Claude Pache <claude.pache at gmail.com>
>> wrote:
>>
>>>
>>>
>>> > Le 19 juil. 2018 à 16:32, Andrea Giammarchi <
>>> andrea.giammarchi at gmail.com> a écrit :
>>> >
>>> > I know it's about subclassing, which is why I've asked why, once
>>> there's no context, the default/base one is not considered, but since
>>> everyone came back with the subclassing issue, which is actually what I've
>>> said myself on twitter about the current state, how about changing all
>>> public static methods that need it, to be getters ?
>>> >
>>> > ```js
>>> > class Promise {
>>> > #resolve(...args) {
>>> > return this.nativeImplementation(...args);
>>> > }
>>> > get resolve() {
>>> > return #resolve.bind(this);
>>> > }
>>> > }
>>> > ```
>>> >
>>> > we could argue `Promise.resolve === Promise.resolve` should be
>>> preserved, as behavior, so that we need a lazy defined getter ... **but**
>>> why not making public static restructuring from known constructors work
>>> regardless, under all circumstances ?
>>> >
>>>
>>> Nice hack... But it imposes all subclasses of `Promise` that override
>>> the `resolve` method to use a similar trick, because the following will
>>> break:
>>>
>>> ```js
>>> class MyPromise extends Promise {
>>> static resolve() {
>>> // do fancy stuff
>>> return super.resolve()
>>> }
>>> }
>>>
>>> const {resolve} = MyPromise
>>>
>>> resolve() // TypeError: undefined is not an object
>>> ```
>>>
>>> Per the KISS principle, let’s avoid to be clever.
>>>
>>> —Claude
>>>
>>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180720/6679fcf6/attachment.html>
More information about the es-discuss
mailing list