The `super` keyword doesn't work as it should?
Andrea Giammarchi
andrea.giammarchi at gmail.com
Wed Jul 20 10:27:49 UTC 2016
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160720/490f77c1/attachment.html>
More information about the es-discuss
mailing list