简体   繁体   中英

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. 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". If this.id is the value I want, I enter the debugger.

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:

debugger;

This works in Firebug, Chrome's console and 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. 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'. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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