Created
August 9, 2011 15:51
-
-
Save keeguon/1134416 to your computer and use it in GitHub Desktop.
JavaScript Singleton
This file contains hidden or 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
/* Author: | |
- Félix Bellanger <[email protected]> | |
*/ | |
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