Skip to content

Instantly share code, notes, and snippets.

@jeffesp
Created August 31, 2016 15:14
Show Gist options
  • Save jeffesp/6a52027aae64e49d3001376c9fa918f3 to your computer and use it in GitHub Desktop.
Save jeffesp/6a52027aae64e49d3001376c9fa918f3 to your computer and use it in GitHub Desktop.
Javascript Singleton
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