我想在子类中编写一个简单的函数,它只返回它自己的键(而不是父类)。
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]
这可能吗?