class Singleton {
constructor(x){
const instance = this.constructor.instance;
if(instance) {
return instance;
}
this.constructor.instance = this;
}
}
Monostate 单态
class ChiefExecutiveOfficer {
get name(){
return ChiefExecutiveOffice._name;
}
set name(value){
ChiefExecutiveOffice._name = value;
}
get age(){
return ChiefExecutiveOffice._age;
}
set age(value){
ChiefExecutiveOffice._age = value;
}
toString(){
return `CEO的名字是${this.name} ` + `ta的年龄是${this.age}岁`;
}
}
ChiefExecutiveOfficer._name = undefined;
ChiefExecutiveOfficer._age = undefined;