Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafaellucio/de7553c3e0ea0f9d88c02358b86334d6 to your computer and use it in GitHub Desktop.
Save rafaellucio/de7553c3e0ea0f9d88c02358b86334d6 to your computer and use it in GitHub Desktop.
class Logger {
sucesso(message) {
console.log(`SUCESSO: ${message}`)
}
error(message) {
console.error(`ERROR: ${message}`)
}
}
class SingletonLogger {
static _instance
static _createInstance() {
const logger = new Logger()
return logger
}
static getInstance() {
if (!this._instance) {
this._instance = this._createInstance()
}
return this._instance
}
}
const instance1 = SingletonLogger.getInstance()
const instance2 = SingletonLogger.getInstance()
console.log(instance1 === instance2)
// => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment