Created
June 23, 2013 16:57
-
-
Save edubskiy/5845706 to your computer and use it in GitHub Desktop.
Namespaced singletone shortcut
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
// Create global namespace | |
App = {}; | |
// Attach your singletone method as shortcut inside | |
App.Event = (function() { | |
var instance; | |
return function() { | |
if (!instance) { | |
instance = new Event(); | |
} | |
return instance; | |
}; | |
}()); | |
// Then you can use single instance like this (in the case of Event.js): | |
App.Event().on('done' , function() {}); | |
App.Event().trigger('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment