我想像这样在 ES6 类中使用静态类属性(stage-0) -
class Button {
static size = {
SMALL: "SMALL",
BIG: "BIG"
}
}
class UILibrary {
consturctor() {
this.button = new Button();
}
}
// I can't access static properties of a class instance :(
const LibraryA = new UILibrary();
console.log(LibraryA.button.size.SMALL);
什么是最好的选择?
编辑:
这个问题不是关于在 ES6/7 中创建类属性(阶段 0 已经支持),也不是关于创建静态方法。我只是想找到一种允许将类似枚举的对象附加到类实例的模式。因此,没有一个重复的问题建议是有效的。