class Game {
constructor() {
// 公有字段
this.name = "unknown";
this.year = 2000;
}
}
// ES6 之前
function GameES5() {
// 公有字段
this.name = "unknown";
this.year = 2000;
// 私有字段
var developer = "unknown";
}
//Support: TC39: Stage 3, Node: 12+, Chrome: 74+
class GameFields {
// 公有字段
name = "unknown";
year = 2000;
// 私有字段
#developer = "unknown";
showDeveloper() {
console.log(this.#developer);
}
}