小编Est*_*iaz的帖子

确定财产是来自父母还是孩子

我想在子类中编写一个简单的函数,它只返回它自己的键(而不是父类)。

class Parent{
    protected _parentAttribute!: string;
    constructor() {
        this._parentAttribute='test';
    }
}

class Child extends Parent{
    childAttribute!: string;
    constructor() {
        super();
        console.log("My unique child keys are:", Object.keys(this));
    }
}
let child=new Child();
Run Code Online (Sandbox Code Playgroud)

结果: My unique child keys are: [_parentAttribute,childAttribute]

期望的结果:My unique child keys are: [childAttribute]

这可能吗?

javascript typescript

5
推荐指数
1
解决办法
735
查看次数

标签 统计

javascript ×1

typescript ×1