单例模式
class Singleton {
constructor(name) {
this.name = name;
this.instance = null;
}
static getInstance(name) {
if (!this.instance) {
this.instance = new Singleton(name);
}
return this.instance;
}
}
const oA = Singleton.getInstance("hello");
const oB = Singleton.getInstance("world");
console.log(oA === oB);
观察者模式
发布订阅模式