Skip to content

Instantly share code, notes, and snippets.

@jerray
Created September 26, 2014 07:52
Show Gist options
  • Save jerray/065aa7a0099c67c41694 to your computer and use it in GitHub Desktop.
Save jerray/065aa7a0099c67c41694 to your computer and use it in GitHub Desktop.
JavaScript Singleton
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