我有這兩個打字稿類:打字稿覆蓋類的方法,這
class Base {
value: string;
lambdaExample =() => {
this.value = 'one';
}
methodExample() {
this.value = 'two';
}
}
class Child extends Base {
lambdaExample =() => {
super.lambdaExample(); // Error, because I've overwritten (instead of overridden) the method
this.value = 'three'; // ok
}
methodExample() => {
super.methodExample(); // ok
this.value = 'four'; // Error: this refers to window, not to the actual this
}
}
我怎樣寫我的方法,這樣的方式this
引用是可靠的,和我可以重寫方法和調用它們父類?
可能重複的[在打字稿中調用超類的重寫方法](http://stackoverflow.com/questions/30819663/call-an-overridden-method-from-super-class-in-typescript) – smnbbrv
這是不是重複的:該問題是關於在構造函數中調用類方法,而不是關於使用類屬性的重寫方法。 – Jorn
@smnbbrv這個問題與此無關。 –