I read various topics, like this one .
But it really eludes me how to do the following:
I have 4 functions and want them to happen one after another in sequence. Please note that they are in the wrong order to get my point. I want to get a result that will output "1, 2, 3, 4"
function firstFunction(){ // some very time consuming asynchronous code... console.log('1'); } function thirdFunction(){ // definitely dont wanna do this until secondFunction is finished console.log('3'); } function secondFunction(){ // waits for firstFunction to be completed console.log('2'); } function fourthFunction(){ // last function, not executed until the other 3 are done. console.log('4'); }
I tried to figure out callbacks, but am lost :(
Is there an easy way to do this? Like looping through an array ...
javascript callback jquery-callback
tim
source share