开发者

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 开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜