Created
September 26, 2014 07:52
-
-
Save jerray/065aa7a0099c67c41694 to your computer and use it in GitHub Desktop.
JavaScript Singleton
This file contains 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
var Singleton = function() { | |
if (Singleton.prototype._instance) { | |
return Singleton.prototype._instance; | |
} | |
Singleton.prototype._instance = this; | |
}; | |
var a = new Singleton; | |
var b = new Singleton; | |
a === b; // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment