简体   繁体   中英

jquery, javascript and callback timing

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM