杀死无限运行的JavaScript函数 [英] Killing a JavaScript function which runs infinite
本文介绍了杀死无限运行的JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
var runInfinite = function(){
while(1)
{
// Do stuff;
}
};
setTimeout(runInfinite, 0);
是否有可能破坏运行infinite的runInfinite函数形式?我的意思是可以在不使用标志或return语句的情况下从另一个函数中杀死该函数吗?
Is it possible to break this runInfinite function form running infinite? I mean is it possible to kill this function from another function without using a flag or return statement?
推荐答案
<答案是否定的。由于JavaScript是单线程的(除非您使用的是不太常见的实现,我对此表示怀疑),所以没有什么可以打破外部的循环(或任何其他代码块)。
The answer is no. Since JavaScript is single-threaded ( unless you are using some less common implementation which I doubt ) nothing can break a loop ( or any other block of code ) from outside.
这篇关于杀死无限运行的JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文