Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2014 12:43
Show Gist options
  • Save anonymous/8351305 to your computer and use it in GitHub Desktop.
Save anonymous/8351305 to your computer and use it in GitHub Desktop.
Various methods of calling functions defined out of scope.
// Add to global namespace
$(document).ready(function(){
window.coolfunc = function(arg){
alert(arg);
}
coolfunc('Hi!');
});
coolfunc('oh hi too!');
// Declare your own name space (http://stackoverflow.com/a/3402906/662826)
$(document).ready(function(){
MyApp = { //Example from SO shows var MyApp, but this doesn't make the var global, so for use within .ready() we must omit 'var'
showMessage: function(arg){
alert(arg);
}
};
MyApp.showMessage();
});
MyApp.showMessage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment