I’m trying to run iwillbeawebdev.other after the iwillbeawebdev.load function has finished. However iwillbeawebdev.other runs as soon as iwillbeawebdev.load starts running.
I’m not sure why you’re doing all of the functions-inside-functions stuff. Are you specifically trying to learn something? Or is the idea just to execute a function after another function? cause…
iwbwd.load();
iwbwd.other();
will do that, when both functions are synchronous.
you’ve got the structure of a callback in your script; usually it’s obfuscated into a framework so that you wouldnt directly call the callback, the framework would take care of it for you automatically;
see jquery’s ajax.success for an example of an implicit callback; you never actually CALL success, you just define it and let the framework call it when it needs it.
for an explicit callback, it works just as you have it in your .load function, take a parameter that is a function, and call it at the end of your current function.
var x = 1;
function imafunc(cbfunc) {
//Do Some Stuff
x = x+1;
cbfunc();
}
function dolater() {
//Do other stuff!
console.log(x);
}
dolater(); //Logs 1, because we havent changed x yet.
imafunc(dolater); //Logs 2, because it changes x, and then invokes the logger function.
Also, be careful because jquery already specifies a .load() function on selectors.