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 ?
yes this is a good way. you can use:
(function(){});
if you are not using javascripts libs other than jQuery for readyThe following execute once the document has been loaded:
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/
you can let function1 call a second function then the third one, and so on. but it is allways line by line