Created
December 28, 2017 17:11
-
-
Save rafaellucio/de7553c3e0ea0f9d88c02358b86334d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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