简体   繁体   English

Javascript使用Firebug观察基于表达式的断点?

[英]Javascript watch expression based breakpoints with Firebug?

Working through some event routing right now and there's a lot of debugging steps. 现在正在完成一些事件路由,并且有很多调试步骤。

I know about using "debugger" in the javascript and putting that after a conditional, and that is useful. 我知道在javascript中使用“调试器”并将其放在条件之后,这很有用。 I also know about right clicking a break point to add a test expression which is even better. 我也知道右键单击一个断点来添加一个更好的测试表达式。 However... I have no idea where this thing is going to take me and I am starting to wear out my function keys. 但是......我不知道这件事会带给我什么,我开始磨损我的功能键。 Is there any way to add a breakpoint to a watch expression? 有没有办法在监视表达式中添加断点?

Basically the idea is this, within the enclosure scope, I want to check for a variable called "this.id". 基本上这个想法是这样的,在封装范围内,我想检查一个名为“this.id”的变量。 If this.id is the value I want, I enter the debugger. 如果this.id是我想要的值,我进入调试器。

Any ideas? 有任何想法吗?

Thanks 谢谢

Wanted to add that Didier's answer below solved my problem as they outlined in the article for decorating "Function". 想要补充说下面的迪迪埃的答案解决了我们在装饰“功能”的文章中概述的问题。 This will most likely be the path of least resistance for searching all functions for the value I want. 这很可能是搜索我想要的所有函数的阻力最小的路径。

Function.prototype.debug = function(){   
   var fn = this; 
   return function(){     
       if (debugme) debugger; 
       return fn.apply(this, arguments);     
   }; 
};

如果您指的是“ 条件断点 ”,也就是说只有在语句为真时才暂停执行的断点,您可以通过右键单击一行脚本并选择“编辑断点条件...”来执行此操作。 ,然后添加你想要触发断点的语句,例如this.id ===“foo”;

To programmatically break on javascript code, you can use the following statement: 要以编程方式中断javascript代码,可以使用以下语句:

debugger;

This works in Firebug, Chrome's console and IE. 这适用于Firebug,Chrome的控制台和IE。

So following your question, you could do something like: 因此,按照您的问题,您可以执行以下操作:

if (this.id === "myId")
    debugger;

The following article is pretty useful. 以下文章非常有用。

I'm not 100% clear on how what you need is different from a conditional breakpoint. 我不是100%清楚你需要什么与条件断点不同。 eg adding 例如,添加

 var watchVar = this.id

then setting a condition for the breakpoint of 然后设置断点的条件

watchVar == someInt 

should work, no? 应该工作,不是吗?

If not, you can break on property change by placing a normal breakpoint somewhere in the closure. 如果没有,您可以通过在闭包中的某处放置一个普通断点来打破属性更改。 When you hit it, look for this.id in the watch pane, right click it and choose 'break on property change'. 当你点击它时,在监视窗格中查找this.id,右键单击它并选择“中断属性更改”。 At the moment, that's about as far as you can go, but it doesn't allow you to specify some id values and not others. 目前,这是你可以去的,但它不允许你指定一些id值而不是其他值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM