Skip to content

Instantly share code, notes, and snippets.

@wulymammoth
Created August 13, 2014 03:14
Show Gist options
  • Select an option

  • Save wulymammoth/a99a00a48bbb7656b0ec to your computer and use it in GitHub Desktop.

Select an option

Save wulymammoth/a99a00a48bbb7656b0ec to your computer and use it in GitHub Desktop.
Singleton Constructor
var MakeSingleton = function(){
var obj;
return function() {
if( obj ){
return obj;
} else{
obj = this;
}
};
};
var Singleton = MakeSingleton();
var x = new Singleton();
var y = new Singleton();
x === y;
// var x = new Singleton();
// var y = new Singleton();
// x === y => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment