Skip to content

Instantly share code, notes, and snippets.

@seb-thomas
Forked from anonymous/gist:8351305
Last active January 2, 2016 19:39
Show Gist options
  • Save seb-thomas/8351336 to your computer and use it in GitHub Desktop.
Save seb-thomas/8351336 to your computer and use it in GitHub Desktop.
// Add to global namespace
$(document).ready(function(){
window.coolfunc = function(arg){
alert(arg);
}
coolfunc('Hi!');
});
coolfunc('oh hi too!');
// Declare your own name space with object (http://stackoverflow.com/a/3402906/662826)
$(document).ready(function(){
// Example from SO shows var MyApp, but this doesn't make the var global,
// so for use within .ready() we must omit 'var'
MyApp = {
showMessage: function(arg){
alert(arg);
}
};
MyApp.showMessage('hi');
});
MyApp.showMessage('hello');
// Closures? (from link above)
// Self invoke? (http://stackoverflow.com/a/17567235/662826)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment