This question already has an answer here:
I wanna synchronized functions just like jQuery's $.ajax({ .., async: false, .. });
.
function A() { lalala .. };
function B() { dadada .. };
function C() { .. };
, those all including some effect like fadeIn, Out, slide... etc.
However I just found if those functions called like below..
A();
B();
C();
All effect start at almost same time. In my understanding, this happens because the function called synchronously but it doesn't mean that function B() started after function A() was completely finished.. right?
Then, how can I make those functions work in order?
I found a way use callback function but it's not enough for me..
I suppose that each function makes some ajax request or animation
For a more detailed answer please explain what your functions do
You have indeed specified three synchronous functions, meaning B will only trigger when A has finished.
However, doing asynchronous tasks like starting an animation won't stop A from completing, so it appears that B isn't waiting until completion.
Read about jQuery Deferreds. Deferreds is a design pattern, so it's not specific to jQuery, however they have a great implementation.
Have a look at using
jQuery $.Deferred();
That can allow you to run each function in sequence, one waiting after the other. For example:
Using
defer.resolve();
means you can control when the function yields execution to the next function.