c() will always be called after b() because you placed it there.
The real question is whether or not c() will be called before b() is finished.
If b() is not an async function, then your code is perfect. c() will be called once b() is finished.
function A(){
b(); // *not* async
c();
}
However, if b() is async in nature, you need to provide c() as a callback.
function A(){
b(c); // async
}
function b(cb){
// ...
cb(); // cb() doesn't need "this"
}
Since c() is a bound method, you need to also pass the context (this) to b().
function A(){
/* extract and save context, somehow */
b(c, context); // async
}
function b(cb, context){
// ...
cb.call(context); // cb() doesn't need "this"
}
I don't want to mess up.
If you don't want to play with context passing, you can use a Promise.
function A(){
b().then(function() {
// run "c()" only when "b()" is finished and there were no errors
c();
});
}
function b(){
// ...
// "b()" is *not* async
return Promise.resolve();
}
function b(){
// ...
// "b()" is async
var whenDone = new Promise(function(resolve, reject) {
performAsyncTask(resolve);
})
return whenDone;
}
But wait, there's more.
If you want bleeding edge tech, you can always use async/await
async function A(){
await b(); // VOILA! it's that easy
c();
}
These are the general basic strategies. Of course, you can try to mix-n-match them or try to figure out something new that suits your needs.