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);
};
};
In Script tab of FireBug, You need to select _display file. It has the code written in javascript section of jsFiddle. Just put breakpoint and debug easily.
To the left of the code you can see the line number of this particular line of code, which is 32. Click on 32. DevTools puts a blue icon on top of 32. This means that there is a line-of-code breakpoint on this line.
See Pause Your Code With Breakpoints to learn when and how to use each type. One common cause of bugs is when a script executes in the wrong order. Stepping through your code enables you to walk through your code's execution, one line at a time, and figure out exactly where it's executing in a different order than you expected.
Overview of when to use each breakpoint type # Breakpoint Type Use This When You Want To Pause... Line-of-code On an exact region of code. Conditional line-of-code On an exact region of code, but only whe ... DOM On the code that changes or removes a sp ... XHR When an XHR URL contains a string patter ... 3 more rows ...
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.
If you are referring to "conditional breakpoints", that is to say a breakpoint that only pauses execution when a statement is true, you can do this by right-clicking on a line of script, and selecting "Edit Breakpoint Condition...", then adding the statement you want to trigger the breakpoint, e.g., this.id === "foo";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With