class User {
userId = Math.floor(Math.random() * 10);
constructor() {
this.userId2 = Math.floor(Math.random() * 10);
}
}
let user = new User();
console.log(user.userId);
console.log(user.userId2);
위코드에서
클래스필드로 정의된 프로퍼티하고
생성자로 정의된 프로퍼티하고 차이점이 뭔지 알 수 있을까요?
(사용하는데 있어서)
없어요. 재생성시 갱신된다 정도 new class (args) 이런식으로 줘서 설정가능함
동일하게 작동함.
클래스 필드로 정의하는 속성은 아직 표준은 아니긴 해.