Last active
December 17, 2015 13:29
-
-
Save pazguille/5617594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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