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


当前回答

调试器是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没有变化。

其他回答

你也可以使用debug(function),在函数被调用时中断。

命令行API参考:调试

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

截图:

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

我不推荐调试器;如果你只是想杀死和停止javascript代码,因为调试器;将只是暂时冻结你的javascript代码,而不是永久停止它。

如果你想在你的命令下正确地杀死和停止javascript代码,请使用以下命令:

抛出新的错误(“这个错误消息出现是因为我放置了它”);

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

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

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

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