Skip to content

Instantly share code, notes, and snippets.

@akushnikov
Created March 30, 2016 10:35
Show Gist options
  • Save akushnikov/9fbb13d53a2385fd60378aedd2901baf to your computer and use it in GitHub Desktop.
Save akushnikov/9fbb13d53a2385fd60378aedd2901baf to your computer and use it in GitHub Desktop.
ES6 singleton
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