Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created February 15, 2014 16:40
Show Gist options
  • Save adohe-zz/9021757 to your computer and use it in GitHub Desktop.
Save adohe-zz/9021757 to your computer and use it in GitHub Desktop.
singleton implementation in JavaScript
var app = function() {
//Private stuff
var instance;
//Init method just like a constructor
function init() {
//Return an empty object
reutn {};
}
//Public
return {
getInstance: function() {
if(!instance)
instance = init();
return instance;
},
destory: function() {
instance = null;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment