class User {
static staticMethod() {
alert(this === User);
}
}
User.staticMethod(); // true
class에 static키워드를 사용하여 해당 프로퍼티는 static 프로퍼티가 된다.
class Article {
constructor(title, date) {
this.title = title;
this.date = date;
}
static createTodays() {
// this는 Article입니다.
return new this("Today's digest", new Date());
}
}
let article = Article.createTodays();
alert( article.title ); // Today's digest