The `super` keyword doesn't work as it should?
Logan Smyth
loganfsmyth at gmail.com
Wed Jul 20 14:59:44 UTC 2016
Joe, yes sorry, my mistake. `a` should have `__proto__: b`, and `b` should
have `__proto__: c` in my example, that's what I get for not validating it
better. Each could `return` but since `a.method` was the only one I called,
it was the only one I put the `return` in.
On Wed, Jul 20, 2016 at 3:27 AM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> For implementation sake, this is a quick'n'dirty approach that brings a
> dynamically resolved `super` to any object or prototype:
> https://gist.github.com/WebReflection/ee4695c107339e039878b02afb90dc0d
>
> Usage example:
> ```js
> function A() {
> console.log(this.constructor.name);
> }
> A.prototype.method = function () {
> console.log('method from ' + this.constructor.name);
> };
>
> function B() {
> this.super();
> console.log(this.constructor.name);
> }
> B.prototype = Object.create(A.prototype, {constructor: {value: B}});
> withSuperContext(B.prototype).method = function () {
> this.super.method();
> console.log('method from ' + this.constructor.name);
> };
>
> function C() {
> this.super();
> console.log(this.constructor.name);
> }
> C.prototype = withSuperContext(
> Object.create(B.prototype, {constructor: {value: C}})
> );
> C.prototype.method = function () {
> this.super.method();
> console.log('method from ' + this.constructor.name);
> };
>
> var c = new C;
> // will log
> // A
> // B
> // C
>
> c.method();
> // method from A
> // method from B
> // method from C
>
> ```
>
> Best Regards
>
>
> On Wed, Jul 20, 2016 at 9:06 AM, medikoo <medikoo+mozilla.org at medikoo.com>
> wrote:
>
>> Joe, see this post:
>>
>> http://mozilla.6506.n7.nabble.com/Making-quot-super-quot-work-outside-a-literal-td90457.html#a90551
>>
>> There are some explanations there on why super was implemented as
>> something
>> /static/ and not /dynamic/
>>
>>
>>
>> --
>> View this message in context:
>> http://mozilla.6506.n7.nabble.com/The-super-keyword-doesn-t-work-as-it-should-tp357032p357113.html
>> Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at
>> Nabble.com.
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> 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/20160720/645ace07/attachment.html>
More information about the es-discuss
mailing list