Created
February 15, 2014 16:40
-
-
Save adohe-zz/9021757 to your computer and use it in GitHub Desktop.
singleton implementation in JavaScript
This file contains 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
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