views:

48

answers:

2

var blah = Some.Thing(data, function(a,b) { // code here });

Some.Thing = function(data, callback) {

  if(...) {
     var a = Other.Thing(data, function() {
       // code here

        callback();
        return;
     });    
  }

  callback();
};

My question is, will the part that says //code here fire only after everything else and their callbacks fire?

The //code here part seems to fire, and there seems to be some timing issue.

+1  A: 

You're not actually using callback anywhere in Some.Thing, so it's impossible to say. But yes, generally, unless something actually calls callback, the code within it is not executed. It is evaluated (parsed), but not executed.

T.J. Crowder
A: 

That is impossible to tell from the code you supplied.
The method callback can either be called while on the same stack, or its execution might be deferred due to ajax or setTimeout being used (asynchronous).

If being deferred, then it would be called only after the main method has completed and the thread going back to idle.

Sean Kinsey