我有3门课程:
class A{
DoStuff(){
return "Called from A";
}
}
class B extends A {
constructor(){
super();
var baseDoStuff = super.DoStuff;
this.DoStuff = function(){
return baseDoStuff() + " and Called from B";
}
}
}
class C extends B {
constructor(){
super();
var baseDoStufffff = super.DoStuff;
this.DoStuff = function(){
return baseDoStufffff() + " and Called from C";
}
}
}
我本来期望类C的DoStuff()会调用B的DoStuff()(而B的DoStuff()会调用A的),
然而,只调用C上的DoStuff()却仅返回"Called from A and Called from C"。我在这里做错了什么?难道不应该也调用B的方法吗?
您可以在此处找到一个可工作的示例: