我想通过代码强制Chrome调试器在一行上中断,或者使用某种注释标记,例如console.break()。


当前回答

你也可以设置debug(functionName)来调试函数。

https://developers.google.com/web/tools/chrome-devtools/javascript/breakpoints#function

其他回答

调试器是EcmaScript保留的关键字,从ES5开始提供可选语义

因此,它不仅可以在Chrome中使用,还可以通过节点调试myscript.js在Firefox和node .js中使用。

标准说:

Syntax DebuggerStatement : debugger ; Semantics Evaluating the DebuggerStatement production may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect. The production DebuggerStatement : debugger ; is evaluated as follows: If an implementation defined debugging facility is available and enabled, then Perform an implementation defined debugging action. Let result be an implementation defined Completion value. Else Let result be (normal, empty, empty). Return result.

ES6没有变化。

在“Scripts”选项卡上,转到代码所在的位置。在行号左侧,单击。这将设置一个断点。

截图:

然后,您将能够在正确的选项卡中跟踪断点(如屏幕截图所示)。

正如其他人已经说过的,调试器;才是正确的选择。 我写了一个小脚本,你可以在浏览器的命令行中使用它来设置和删除函数调用之前的断点: http://andrijac.github.io/blog/2014/01/31/javascript-breakpoint/

你可以使用调试器;在你的代码中。如果开发人员控制台是打开的,执行将中断。它也适用于firebug。

这个Git预提交钩子可以从merb项目中删除错误的调试器语句

如果想在提交时删除调试器断点,可能有用