hi,
i want to know how to implement virtual functions in cocos creator - typescript. so basically when i call a virtual function of the base class it should execute the function with the same signature in the derived class (if it overrides the method in the base class) . i also want to be able to call the base class function from the derived class e.g.
super.SetUI();
or
base.SetUI();
thank you!
There is no concept of virtual function in typescript, TS uses “prototype chain” to achieve similar goal, as long as there is a method with the same signature in the derived class, it will overwrite the method in the base class. for example:
class TestBase {
SetUI (): void {
// do some thing
}
}
class TestDerived extends TestBase {
SetUI (): void {
super.SetUI(); // invoke the method of base class
// do some thing customized
}
}