Created
August 31, 2016 15:14
-
-
Save jeffesp/6a52027aae64e49d3001376c9fa918f3 to your computer and use it in GitHub Desktop.
Javascript Singleton
This file contains 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 Singleton { | |
static get instance() { | |
if (!this._instance) { | |
this._instance = Date(); | |
} | |
return this._instance; | |
} | |
} | |
console.log(Singleton.instance); | |
setTimeout(x => console.log(Singleton.instance), 5000); | |
// OUTPUT - 5 seconds clock time elapsed between: | |
// Wed Aug 31 2016 11:13:27 GMT-0400 (DST) | |
// Wed Aug 31 2016 11:13:27 GMT-0400 (DST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment