我有这两个打字稿类:打字稿覆盖类的方法,这
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这个问题与此无关。 –