Created
March 30, 2016 10:35
-
-
Save akushnikov/9fbb13d53a2385fd60378aedd2901baf to your computer and use it in GitHub Desktop.
ES6 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 { | |
constructor() { | |
this.foo = 5; | |
} | |
static get Instance() { | |
if (this.instance == null || this.instance == undefined) { | |
this.instance = new Singleton(); | |
} | |
return this.instance; | |
} | |
} | |
console.log(Singleton.Instance.foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment