我从其他类继承的类继承了其他类,如下所示:
class RootClass {
call(): void;
}
class SubClass extends RootClass {
call(): void:
}
class MyClass extends SubClass {
call(): void {
RootClass.call(); // how to access parent class's parent class?
}
}
似乎C++
可以执行以下操作:RootClass::call()
,call
方法不是静态的。
我知道有super
来访问基类的属性和方法,无论如何直接访问root
类方法?
谢谢!
答案 0 :(得分:1)
您可以使用prototype
的{{1}}访问该功能,并使用RootClass
或call
apply
答案 1 :(得分:1)
静态和实例调用将如下所示:
class RootClass {
call(): void {
console.log("RootClass")
}
static staticCall(): void {
console.log("RootClass static")
}
}
class SubClass extends RootClass {
call(): void {
super.call(); // run instance method of RootClass
console.log("SubClass")
}
}
class MyClass extends SubClass {
call(): void {
super.call(); // run instance method of SubClass
RootClass.staticCall(); // run static method of RootClass
}
}
var m = new MyClass();
m.call();