We use the revealing module pattern to organise stuff into "namespaces". Some of the initialisation code (for the jQuery Validation plugin) should only be called after document load.
Namespace.Foo.Bar = (function($) {
var init = function() {
$(function() { // <--- within DOM ready wrapper it never runs
$.validator.setDefaults({
// ...
});
});
(function(){ // <--- but within an IIFE it will run
$.validator.setDefaults({
// ...
});
})();
};
init();
// public functions/variables
return {
};
}(jQuery));
When the $.validator.setDefaults
bit is within a DOM ready wrapper, it never gets called, but when it is within an IIFE then it does get called.
Why? What is the "best" way to mark some module code to run after DOM ready?
EDITS: made sample code more illustrative of the problem