I am using a namespace to hold some functions in JavaScript, all of which I want to run with window.onload. If I do this, everything works as expected:
SiteFn = {};
(function(context) {
context.firstFn = function() {
// do stuff
};
context.secondFn = function() {
// do stuff
};
})(SiteFn);
window.onload = function() {
SiteFn.firstFn();
SiteFn.secondFn();
};
However, when I try to group them into a single init function, it seems to get called before window.onload:
SiteFn = {};
(function(context) {
context.firstFn = function() {
// do stuff
};
context.secondFn = function() {
// do stuff
};
context.start = function() {
context.firstFn();
context.secondFn();
};
})(SiteFn);
window.onload = SiteFn.start();
What am I doing wrong?
you don’t need to actually call the method, just give a reference to it, and so