debugger

debugger 语句调用任何可用的调试功能,例如设置断点。如果没有可用的调试功能,则此语句无效。

¥The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.

语法

¥Syntax

js
debugger;

示例

¥Examples

使用调试器语句

¥Using the debugger statement

以下示例显示了插入了 debugger 语句的代码,以便在调用函数时调用调试器(如果存在)。

¥The following example shows code where a debugger statement has been inserted, to invoke a debugger (if one exists) when the function is called.

js
function potentiallyBuggyCode() {
  debugger;
  // do potentially buggy stuff to examine, step through, etc.
}

当调用调试器时,执行会在 debugger 语句处暂停。它就像脚本源中的断点。

¥When the debugger is invoked, execution is paused at the debugger statement. It is like a breakpoint in the script source.

A browser with developer tools open to the debugger panel showing how execution is paused at the debugger statement to allow close inspection of variables, scopes, events, etc.

规范

Specification
ECMAScript Language Specification
# sec-debugger-statement

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also