Namespace func vs onready
by Edward
JavaScript
// this is an isolated namespace that is run on parse time.
(function() {
// these two functions are ONLY available withing this block
// thus can be REALLY generic names w/o worrying about name collisions with other librries
function test() {
}
function Blah() {
}
// this is exposed via the global window object
window.exportedFunc = function() {
test();
Blah();
}
})(); // these two extra () make this namespace run on parse time.
$(function() {
// This is an anonymous function registered with jquery to be run "on ready"
});
// this works (it was exported)
expotedFunc();
// these do not
test();
Blah();