Created
October 4, 2013 21:55
-
-
Save geastwood/6833472 to your computer and use it in GitHub Desktop.
js singleton template
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
window.singleton = (function(){ | |
var instance; | |
var init = function() { | |
return Math.random(); | |
}; | |
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