在 Javascript 中以编程方式控制断点?
是否可以在任何浏览器中使用任何插件以编程方式启用或禁用代码中的断点?
我已经知道如何设置条件断点,但我真的对通过代码设置它们感兴趣。
Is it possible, in any browser, using any plugin, to enable or disable breakpoints in your code programmatically?
I already know about setting conditional breakpoints, but I'm really interested in setting them via code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您可以添加对 __checkDebug(); 之类的函数的调用;它将检查全局(或半全局)变量,当所述变量为真时,调用调试器。
您关心调试的所有函数都会像这样:
然后,您可以更进一步,在代码执行时动态装饰函数,如下所示:
现在,任何时候调用 foo ,如果 debugme 变量都将调用调试器是真的。
另一种选择是构建一个 javascript 构建系统,在每个函数声明后注入调用 - 这需要一个语法解析器,但如果您只想修改函数,那么针对该用例编写一个简单的标记器非常容易 - 但我'这由你决定。
First you could add a call to a function like __checkDebug(); which will check for a global (or semi-global) variable and when said variable is true, call debugger.
all of your functions you're concerned about debugging would be like so:
You can then take it a little further and dynamically decorate functions while the code is being executed like so:
now any time foo is called it will call debugger if the debugme variable is truthy.
Another option would be to build a javascript build system that injects the call after every function declaration - this requires a syntax parser but if you're only looking to modify functions a simple tokenizer for that use case is pretty easy to write - but I'll leave that up to you.
您可以在代码中使用
debugger;
为firebug设置断点。例如:Firebug 会自动停止在这个关键字上。
You can use
debugger;
in code to make breakpoint for firebug. For example:And firebug automatically stops on this keyword.
看一下 FireBug 函数 debug(fn) & undebug(fn) 名称,在指定函数的第一行设置断点。
请参阅第 6 点:
http://michaelsync.net/ 2007/09/30/firebug-tutorial-script-tab-javascript-调试
Have a look at the FireBug functions debug(fn) & undebug(fn) names which set a breakpoint on the first line of the named function.
See point #6:
http://michaelsync.net/2007/09/30/firebug-tutorial-script-tab-javascript-debugging