我想通过代码强制Chrome调试器在一行上中断,或者使用某种注释标记,例如console.break()。
当前回答
在“Scripts”选项卡上,转到代码所在的位置。在行号左侧,单击。这将设置一个断点。
截图:
然后,您将能够在正确的选项卡中跟踪断点(如屏幕截图所示)。
其他回答
这个Git预提交钩子可以从merb项目中删除错误的调试器语句
如果想在提交时删除调试器断点,可能有用
调试器是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没有变化。
设置按钮点击监听器并调用调试器;
例子
$("#myBtn").click(function() {
debugger;
});
Demo
http://jsfiddle.net/hBCH5/
JavaScript中调试的资源
http://www.laurencegellert.com/2012/05/the-three-ways-of-setting-breakpoints-in-javascript/ http://berzniz.com/post/78260747646/5-javascript-debugging-tips-youll-start-using-today
正如其他人已经说过的,调试器;才是正确的选择。 我写了一个小脚本,你可以在浏览器的命令行中使用它来设置和删除函数调用之前的断点: http://andrijac.github.io/blog/2014/01/31/javascript-breakpoint/
这是可能的,你想这么做的原因有很多。例如,在页面加载开始时调试javascript无限循环,会阻止chrome开发人员工具集(或firebug)正确加载。
参见第2节
http://www.laurencegellert.com/2012/05/the-three-ways-of-setting-breakpoints-in-javascript/
或者只是在所需的测试点向代码中添加一行包含调试器字样的代码。
推荐文章
- Babel 6改变了它导出默认值的方式
- 如何配置历史记录?
- ES6模板文字可以在运行时被替换(或重用)吗?
- [Vue警告]:找不到元素
- 卸载Chrome开发工具
- 可以在setInterval()内部调用clearInterval()吗?
- AngularJS控制器的生命周期是什么?
- 无法读取未定义的属性“msie”- jQuery工具
- 我的蛋蛋怎么不见了?
- JavaScript中的排列?
- JavaScript中有睡眠/暂停/等待功能吗?
- 如何触发自动填充在谷歌Chrome?
- CSS变换,锯齿边缘在铬
- 如何禁用文本选择使用jQuery?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?