-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Call base class property via super #4465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
IF "super is referring to the prototype object" THEN
alert gets "2 | undefined | undefined". This means super DOES NOT represent prototype, but instance (kind of parent instance, but still instance). IF "super is referring to the base object instance" THEN |
"...super is referring to the prototype object of a super class" class MyBase {
getValue(): number { return 1; }
get value(): number { return 1; }
}
class MyDerived extends MyBase {
constructor() {
super();
const f1 = super.getValue();
const f2 = super.value;
}
}
var d = new MyDerived();
var f3 = d.value; is compiled to: var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var MyBase = (function () {
function MyBase() {
}
MyBase.prototype.getValue = function () { return 1; };
Object.defineProperty(MyBase.prototype, "value", {
get: function () { return 1; },
enumerable: true,
configurable: true
});
return MyBase;
})();
var MyDerived = (function (_super) {
__extends(MyDerived, _super);
function MyDerived() {
_super.call(this);
var f1 = _super.prototype.getValue.call(this);
var f2 = _super.prototype.value;
}
return MyDerived;
})(MyBase);
var d = new MyDerived();
var f3 = d.value; Look over here: live example |
missed your point, (everything that i said is still valid too :) ) |
See #338 |
Please do not close this as I'm targeting ES6. |
Good point - we should at least allow this in ES6 |
Thanks! |
#5860 lifts the restriction for ES6, we still need a separate proposal for the downlevel emit |
return GetPropertyDescriptor(base, 'Name').get.call(this); // getter call The above works in plain javascript. It looks really ugly. Typescript would make it look a little nicer, perhaps using the super keyword. |
Maybe a bit late, but I was able to access I wanted to override a getter of my class Base {
get value() {
return 'a'
}
}
class CustomBase extends Base {
get value() {
return super['value'] + 'b';
}
} |
@jsep this is very helpful, do you have any idea why the index operator is allowed but calling |
In following code:
disallowing the line "const f2 = super.value;" to be valid is... plain stupid.
What is the scenario where this behavior is valid?
The text was updated successfully, but these errors were encountered: