This is for vanilla JavaScript. I wan't a function to execute as soon as another function has completely finished. Right now I actually have something that works, but I suppose it can be done better:
setTimeout(function () {
// does things with the variables a, b(array) and c
}, 500);
function happySunshine(some inparameters){
// calculates and sets variables a, b(array) and c
}
The happySunshine function must unfortunately lay after my setTimeout function in the order, this cannot change.
Now this works because the happySunshine function will have executed and completed it's tasks during the half second that setTimeout is set to wait before executing.
So... I wan't to know. Is there a way to make a function that is first in the order, wait until another function (later in the order) is completely finished before it executes?
Important to note is that these functions cannot be in the same scope.
setTimeout()call necessary?var myFun = function(){ ... code ..}and call it then from happySunshine. Internally that is what JS engine is doing with setTimeout