> Le 19 juil. 2018 à 16:32, Andrea Giammarchi <[email protected]> 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
[email protected]
https://mail.mozilla.org/listinfo/es-discuss