나는과 같이 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);
이에 대한 최선의 대안은 무엇인가?
편집 :
이 질문은 이미 단계-0에서 지원됩니다 ES6/7에 클래스 속성을 만드는 방법에 대해도 정적 메소드를 만드는 방법에 대해 없습니다. 클래스 인스턴스에 열거 형 객체를 첨부 할 수있는 패턴을 찾으려고합니다. 따라서 중복 된 질문 제안 중 어느 것도 유효하지 않습니다.
'왜 이해가 안 돼요 '- 자바와 자바 스크립트는 완전히 다른 언어입니다 –
https://esdiscuss.org/topic/define-static-properties-with-the-prototype-properties-with-the-class-syntax –
@ JaromandaX Lol, 그건 사실이야. 그러나 모범 사례 관점에서 그렇게하는 이유가 있는지 알고 싶습니다. –