Skip to content

Instantly share code, notes, and snippets.

@pazguille
Last active December 17, 2015 13:29
Show Gist options
  • Save pazguille/5617594 to your computer and use it in GitHub Desktop.
Save pazguille/5617594 to your computer and use it in GitHub Desktop.
/**
* Singleton Pattern
*/
function Singleton(options) {
if (!(this instanceof Singleton) && Singleton.getInstance === undefined) {
Singleton.getInstance = new Singleton();
return Singleton.getInstance;
}
if (Singleton.getInstance !== undefined) {
return Singleton.getInstance;
}
this.init();
}
Singleton.prototype.init = function () {
// Some code!
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment