Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Created March 23, 2018 23:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Dammmien/f76b304a51b23b1bc9059330c84d0caa to your computer and use it in GitHub Desktop.
JavaScript Singleton design pattern
class Singleton {
constructor() {
if (typeof Singleton.instance === 'object') {
return Singleton.instance;
}
Singleton.instance = this;
return this;
}
}
const instance = new Singleton();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment