递归函数中的setTimeOut函数会导致堆栈溢出吗? [英] Will setTimeOut function in recursive function cause stack overflow?
本文介绍了递归函数中的setTimeOut函数会导致堆栈溢出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下函数最终会导致堆栈被推翻吗?
Does the following function cause stack overthrow eventually?
var isFinish= false;
function foo(){
// ajax call
//in ajax success
success: function(response){
setTimeout(function(){
if (!isFinish)
{
foo();
}
},1000);
}
}
推荐答案
它不应该。 setTimeout
是异步的(可能是你的AJAX请求),所以 foo
能够立即退出。
It shouldn't. setTimeout
is asynchronous (presumably as is your AJAX request), so foo
is able to exit immediately.
如果jQuery的 $。ajax
中有内存泄漏,那就是另一个问题。
If jQuery has memory leaks in its $.ajax
, then that's another issue.
这篇关于递归函数中的setTimeOut函数会导致堆栈溢出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文