我想使用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哈哈,這是真的。但是我想從最佳實踐的角度來看,是否有這樣做的理由。 –