How To Execute A Javascript/jquery Function Only After The Completion Of Another Function?
I know this is a simple question, but I don't really know how to do it. I'm executing two functions in my code, 'luxboxEngine' and 'fitToScreen', the latter of which requires the c
Solution 1:
Use a callback:
luxboxEngine(self , function() { fitToScreen(); });
Solution 2:
like a callback? Pass the function as a argument then call it:
fitToScreen( function(){luxBoxEginie();} );
function fitToScreen( cb ) {
//// do somethings
cb()
}
or
luxboxEngine(self, function (){ fitToScreen(); });
function luxboxEngine( s, cb)} {
// do somethings
cb(); //execute the callback function
}
fitToScreen() is passed as an argument into luxboxEngine(). fitToScreen() waits to to be executed, and runs only when you do: cb()
Solution 3:
luxboxEngine(self); //Executes, returns undefined, nothing happens with return value
fitToScreen(); //The first one is done by the time we get here
Post a Comment for "How To Execute A Javascript/jquery Function Only After The Completion Of Another Function?"