-
-
Save seb-thomas/8351336 to your computer and use it in GitHub Desktop.
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
// 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