I have:
var Init = (function() {
my js goes here
})();
And my js executes correctly when the page is loaded. I also have:
In order for Init
to execute as a function, your code within the self-executing function must return a function, and the only reason to do this is if you need to construct a specific function dynamically dependent upon some data states:
var Init = (function() {
// some code
return function () {
// some dynamic code dependent upon your previous code
};
}());