Javascript Getting RangeError:在setTimeout上超过了最大调用堆栈大小,即使正在调用的函数包装在闭包中
我有以下代码,重复调用时会抛出此错误- RangeError:超出了最大调用堆栈大小Javascript Getting RangeError:在setTimeout上超过了最大调用堆栈大小,即使正在调用的函数包装在闭包中,javascript,closures,stack-overflow,settimeout,Javascript,Closures,Stack Overflow,Settimeout,我有以下代码,重复调用时会抛出此错误- RangeError:超出了最大调用堆栈大小 var timeout = window.setTimeout(function() { onAnimationEnd(null); }, 2000) onAnimationEnd : function(e) { if (e != null) e.stopPropogation(); animatedObject.removeClass(this.tr
var timeout = window.setTimeout(function() {
onAnimationEnd(null);
}, 2000)
onAnimationEnd : function(e) {
if (e != null)
e.stopPropogation();
animatedObject.removeClass(this.triggerClass);
animatedObject.unbind(this.endEventName);
window.clearTimeout(this.timeout);
}
除了直接调用函数外,在哪些可能的情况下会弹出此错误?
此。超时将不起作用,变量timeout
位于另一个作用域中,您可能还应将其作为参数传递:
var timeout = window.setTimeout(function() {
onAnimationEnd(null, timeout);
}, 2000);
onAnimationEnd(e, timeout) {
if (e != null)
e.stopPropogation();
animatedObject.removeClass(this.triggerClass);
animatedObject.unbind(this.endEventName);
window.clearTimeout(timeout);
}
onAnimationEnd做什么?看起来你在做没有终止条件的递归。它做了大量的取消绑定,删除类和窗口。ClearTimeout(超时)请共享所有相关代码。。。您提供的代码不足以帮助您。我还添加了onAnimationEnd的代码。try/catch捕捉到line window.setTimeout上的错误。