【发布时间】:2016-04-28 23:15:14
【问题描述】:
我有这两个 Typescript 类:
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 引用可靠,并且我可以覆盖方法并从父类调用它们?
【问题讨论】:
-
这不是重复的:这个问题是关于在构造函数中调用类方法,而不是关于使用类属性覆盖的方法。
-
@smnbbrv 这个问题与这个问题没有任何关系。
标签: typescript