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