Skip to content

Instantly share code, notes, and snippets.

@edubskiy
Created June 23, 2013 16:57
Show Gist options
  • Save edubskiy/5845706 to your computer and use it in GitHub Desktop.
Save edubskiy/5845706 to your computer and use it in GitHub Desktop.
Namespaced singletone shortcut
// 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