Javascript 停止firefox退出延迟对象的执行

Javascript 停止firefox退出延迟对象的执行,javascript,jquery,firefox,asynchronous,Javascript,Jquery,Firefox,Asynchronous,我有一些异步代码,其中对于给定的延迟对象defObj,我附加了几个我想要执行的函数,如下所示: $.when(defObj).done(function(){ console.log('callback 1'); }); $.when(defObj).done(function(){ console.log('callback 2'); }); $.when(defObj).done(function(){ console.log('callback 3'); }); $.when(defOb

我有一些异步代码,其中对于给定的延迟对象defObj,我附加了几个我想要执行的函数,如下所示:

$.when(defObj).done(function(){ console.log('callback 1'); });
$.when(defObj).done(function(){ console.log('callback 2'); });
$.when(defObj).done(function(){ console.log('callback 3'); });
$.when(defObj).done(function(){ console.log('callback 1'); });
$.when(defObj).done(function(){
    window.setTimeout(function(){console.log('callback 2'); }, 0); 
});
$.when(defObj).done(function(){ console.log('callback 3'); });
在实际代码中,这些函数附加在几个不同的函数中,我调用这些函数来初始化页面

在其他一些异步代码完成后,我希望解析延迟对象并触发所有回调。我手动解析回调:

defObj.resolve();
在chrome中,这可以很好地工作。延迟对象解析并触发所有回调。在firefox中,我在第二次回调中收到某种错误,或者至少,我认为我收到了,因为它没有显示在控制台中。此错误会阻止其他延迟对象的解析,并停止代码的执行。我尝试将代码放入try/catch块:

try{ defObj.resolve(); } catch(e){ console.error(e) };
但是firefox没有进入catch块

有没有办法阻止firefox在完成所有延迟回调之前退出代码执行


如果这看起来不清楚,请告诉我,我将尝试清理它。

我尝试将代码封装在try{}catch{}块中,但没有效果。最终起作用的是,通过window.setTimeout调用将中断为异步代码块的代码移动到时间延迟为零的位置,如下所示:

$.when(defObj).done(function(){ console.log('callback 1'); });
$.when(defObj).done(function(){ console.log('callback 2'); });
$.when(defObj).done(function(){ console.log('callback 3'); });
$.when(defObj).done(function(){ console.log('callback 1'); });
$.when(defObj).done(function(){
    window.setTimeout(function(){console.log('callback 2'); }, 0); 
});
$.when(defObj).done(function(){ console.log('callback 3'); });

这会将导致问题的代码从页面其余部分的流中取出,从而阻止其阻塞执行。我仍然不知道是什么导致firefox停止代码执行,但这是一个不错的解决方法。

您是否尝试过$.whendefObj.donefunction{try{console.log'callback 2';}捕获回调2中的e{console.log Error;};这对我来说是应该的。只是一个评论:$。when更适合于将多个承诺结合在一起。当ndefobj.doneI最终使用window.setTimeout块删除导致firefox停止执行的代码时,您可以只执行defbj.done而不是$。如果您向我们展示有问题的代码,我们可能会帮助您找到真正的答案。杀死firefox的函数的实际代码约为800行。我不想这样做:我严重怀疑所有800条线路都会导致这个问题。我也是,但我还没有时间深入研究并找出确切的问题。800行是我把它隔离的地方。现在我只想阻止任何问题影响代码的其余部分。