我想使用ES6类的静态类属性(0级),像这样 -ES6等效于以下模式?
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);
什么是我们的最佳选择吗?
EDIT:
这个问题是不是在其中在阶段0已经支持ES6/7,创建类属性也没有有关创建的静态方法。我只是想找到一个模式,允许将类枚举对象附加到类实例。因此没有重复的问题建议是有效的。
'我不明白为什么' - java和javascript是完全不相关的语言 –
https://esdiscuss.org/topic/define-static-properties-and-prototype-properties-with-the-class-syntax –
@JaromandaX哈哈,这是真的。但是我想从最佳实践的角度来看,是否有这样做的理由。 –