I need to be able to have a callback on execution of a function after ready
jQuery(document).ready(function() {
execute function 1, only when finish
do function 2
});
what is the good way to do that ?
I need to be able to have a callback on execution of a function after ready
jQuery(document).ready(function() {
execute function 1, only when finish
do function 2
});
what is the good way to do that ?
JavaScript is single-threaded. Nothing happens simultaneously. However, if fn1 is an async call, the thread will execute fn2 often before fn1's return value is ready. That's what makes JavaScript "racy."
If you have multiple aysnc calls in a series, then you either have to manage a series of NESTED callbacks or make a queue using the Active Object pattern. jQuery has one (mentioned). I wrote a library that does this called proto-q: http://code.google.com/p/proto-q/