Super class 从 subclass 调用一个函数

Super class to call a function from a subclass

我有一个基础 class,有两种方法,"A" 和 "B"。

方法 "B" 在基础中调用 "A"。然后我有一个 subclass 覆盖 "A" 方法。当我从 subclass 调用方法 "B" 时,从 base 调用方法 "A"。

有没有办法让 super 从 subclass 调用覆盖的方法?

export class SuperClass {
    A(param: any): string {
        return "A called from base";
    }

    B(param: any): string {
        let value = this.A(param);
        console.log(value);

        return "B called from base";
    }
}

export class SubClass extends BaseClass  {
    A(param: any): string {
        return "A called from subclass";
    }
}

// create a subclass
let bInstance = new B();
bInstance.B(someParam); // I want to call the overriden A in the subclass

PD: "A" in the base class 需要有自己的实现,不能是抽象的

bInstance.B(someParam); // I want to call the overriden A in the subclass

会在子类中调用重写的方法A,因为this会指向SubClass的实例,JS会寻找方法A首先在这个例子中。所以这段代码:

B(param: any): string {
    let value = this.A(param);
    console.log(value);

应该记录 "A called from subclass";