Object Creation Methods
Which creational pattern ensures only one instance exists?
const Singleton = (() => {
let instance;
function createInstance() {
return {
data: [],
add(item) { this.data.push(item); }
};
}
return {
getInstance() {
if (!instance) {
instance = createInstance();
}
return instance;
}
};
})();