Skip to content

Instantly share code, notes, and snippets.

@thebiltheory
Last active September 18, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebiltheory/01788cba933ebb364d71ba0df3d868cb to your computer and use it in GitHub Desktop.
Save thebiltheory/01788cba933ebb364d71ba0df3d868cb to your computer and use it in GitHub Desktop.
Singleton example
/**
* Singleton Pattern
* @returns {Object}
*/
let Planet;
{
let instance;
Planet = function () {
if (instance) {
return instance;
}
this.name = 'Sun';
this.type = 'Star';
}
instance = this;
};
let sun = new Planet();
let star = new Planet();
console.log(sun === star); //True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment