【发布时间】:2018-03-01 18:28:43
【问题描述】:
当每个类都包含同名的方法时,我无法访问层次结构中的方法。
class A {
constructor(private name: string) { }
notify() { alert(this.name) }
}
class B extends A {
constructor() {
super("AAA")
}
notify() {alert("B") }
}
class C extends B {
notify() { alert("C") }
callA() {
this.notify(); // this alerts "C"
super.notify(); // this alerts "B"
// How to call notify() of the class A so it alerts "AAA"?
}
}
new C().callA();
【问题讨论】:
-
没有允许你这样做的结构——但你具体想做什么?覆盖方法时应始终小心。
标签: typescript inheritance ecmascript-6