如何在没有类实例的情况下获取类的属性名称?

时间:2017-05-11 09:09:59

标签: javascript reflection

我有一个班级:

class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}

如何在没有height实例的情况下将属性widthRectangle作为字符串?

1 个答案:

答案 0 :(得分:1)

您仍然必须至少动态创建一个空实例:



class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}

console.log(Reflect.ownKeys(new Rectangle))




相关问题