在JS中暂停在Chrome中的代码执行。可能? [英] Pausing code execution in chrome from within JS. Possible?
问题描述
我能否在JS代码中暂停执行?我正在研究一个简单的基于haxe的调试util,我希望能够通过调用一个util方法来模拟断点,这会触发执行暂停。
Can I pause execution from within JS code? I am working on a simple haxe-based debug util, and I want to be able to simulate breakpoints, by calling a util method which will trigger the execution pause.
推荐答案
不知道这是你想要的,但是在Chrome中(如果安装了Firebug,则为Firefox),你可以使用内置的JavaScript 调试器
声明。这导致执行暂停,并且实际上就像设置断点一样。例如,下面的代码在循环的每一次迭代中都会中断,从而允许您检查 i
的值(愚蠢简单的示例):
Not sure if this is what you're looking for, but in Chrome (and Firefox if Firebug is installed) you can use the built-in JavaScript debugger
statement. This causes the execution to pause, and is effectively like setting a breakpoint. For example, the following would break on every iteration of the loop allowing you to examine the value of i
(stupidly simple example):
for(var i = 0; i < 10; i++) {
debugger;
console.log(i);
}
这篇关于在JS中暂停在Chrome中的代码执行。可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!