Observer & Singleton Patterns
Which code represents a proper Singleton Pattern implementation in modern JavaScript?
class Configuration {
constructor() {
if (Configuration.instance) {
return Configuration.instance;
}
this.config = {};
Configuration.instance = this;
}
static getInstance() {
if (!Configuration.instance) {
Configuration.instance = new Configuration();
}
return Configuration.instance;
}
set(key, value) {
this.config[key] = value;
}
get(key) {
return this.config[key];
}
}