Share
Sign In

싱글턴 패턴

인스턴스를 하나만 유지하기 위해 사용된다.
const Singleton = (() => { let instance; function createInstance() { const object = new Object({name: 'Object Instance'}); return object; } return { getInstance: () => { if (!instance) { instance = createInstance(); } return instance; } }; })(); const instance1 = Singleton.getInstance(); const instance2 = Singleton.getInstance(); console.log(instance1 === instance2); // true