Skip to content

Instantly share code, notes, and snippets.

@keeguon
Created August 9, 2011 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeguon/1134416 to your computer and use it in GitHub Desktop.
Save keeguon/1134416 to your computer and use it in GitHub Desktop.
JavaScript Singleton
/* Author:
- Félix Bellanger <felix.bellanger@gmail.com>
*/
var Singleton = (function() {
var instance = null;
function init(options) {
// Protected methods and variables
options || (options = {});
return {
// Public methods and variables
};
};
return {
getInstance: function() {
if (!instance) {
instance = init();
}
return instance;
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment