开发者

jquery, javascript and callback timing

开发者 https://www.devze.com 2022-12-31 17:02 出处:网络
var blah = Some.Thing(data, function(a,b) { // code here }); Some.Thing = function(data, callback) { if(...) {
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 开发者_StackOverflow中文版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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号