我有一个类:
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
如何在没有 Rectangle
实例的情况下以字符串形式获取属性 height
和 width
?
最佳答案
您至少仍然需要即时创建一个空实例:
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
console.log(Reflect.ownKeys(new Rectangle))
关于javascript - 如何在没有类实例的情况下获取类的属性名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43911142/