编辑代码

class A {
    protected a: string = "a";
    constructor() {
        console.log("父类 constructor 开始", this);
        this.oninit();
        console.log("父类 constructor 结束", this);
    }
    oninit() {
        this.init();
    }

    init() {

    }
}

class B extends A {
    protected a!: string;
    protected b: string = "b";
    
    init() {
        console.log("子类 init 开始", this);
        this.a = "xxx";
        this.b = "xxx";
        console.log("子类 init 结束", this);
    }
    log() {
        console.log("子类 log", this);
    }
}


let b = new B();

b.log();