Questions tagged «single-threaded»

6
为什么setTimeout不取消我的循环?
我想知道一个JavaScriptwhile语句(在Chrome的控制台中)可以在一毫秒内递增一次变量的次数,因此我迅速将此代码段直接写入控制台: var run = true, i = 0; setTimeout(function(){ run = false; }, 1); while(run){ i++; } 问题是它永远运行。 为什么会发生这种情况,我该如何解决?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.