Proper way to wait for one function to finish before continuing?

One way to deal with asynchronous work like this is to use a callback function, eg: function firstFunction(_callback){ // do some asynchronous work // and when the asynchronous stuff is complete _callback(); } function secondFunction(){ // call first function and pass in a callback function which // first function runs when it has completed firstFunction(function() … Read more