The singleton pattern
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);Copy the code
Observer model
Copy the code
Publish and subscribe model
Copy the code