`super === Object.getPrototypeOf(this)` also doesn't work with multiple inheritance.
If interested, it has been solved dynamically in this good'ol library: https://github.com/WebReflection/es-class#es6-ready Regards On Tue, Jul 19, 2016 at 11:03 AM, /#!/JoePea <[email protected]> wrote: > Hi Bergi, yes, so the object that `super` references would work like > `this`, where the value is determined at runtime instead of in a > declaration. Basically, `super === Object.getPrototypeOf(this)` would > actually be true in my examples. It may be due to ["extra overhead"]( > http://disq.us/p/1a56gxj) that `[[HomeObject]]` is only defined during > declaration, but that is at the huge expense of making the language less > intuitive and also more difficult to work with in some cases (for example, > in designing a multiple-inheritance scheme). > > It would simply be great for super to just work as expected in the > examples I gave, which would mean that super would work in tandem and > intuitively with the various ways in which we can create > objects-extending-objects in JS. > > Good news is that making the necessary change to `super` in ES8 or later > is completely backwards compatible with how it currently works. > > I wonder what the performance problems are and if they can be solved. > > */#!/*JoePea > > On Mon, Jul 18, 2016 at 2:46 PM, Bergi <[email protected]> wrote: > >> /#!/JoePea wrote: >> >> Why can't `super` simply be a shortcut >>> for "look up the prototype of the object that the method is called on, >>> then >>> find the `.constructor` property and call it on `this`"? That seems to be >>> simple. >>> >> >> Simple, yes, and broken in the case of multi-level inheritance: >> ``` >> const x = Object.assign(Object.create({ >> method() { >> console.log("parent"); >> } >> }), { >> method() { >> console.log("child"); >> Object.getPrototypeOf(this).method(); // super.method() >> } >> }); >> x.method(); // works as expected >> >> const y = Object.create(x); >> y.method(); // infinite loop/stack overflow >> ``` >> A `super` query must not depend on `this` (only), it must statically >> resolve the object on which the called method is defined. >> >> In constructors, using the prototype of the currenctly called constructor >> for `super()` works well, but you'd need to use `Object.setPrototype` as >> there is currently no declarative way other than `class`es to define >> functions with custom prototypes. >> >> In methods, there would need to be a way to populate the [[HomeObject]] >> other than declaring the method as part of a class/object literal. >> >> Kind regards, >> Bergi >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

