views:

68

answers:

4

can a Javascript debugger do "when this variable is read", break point there, like a C / C++ debugger?

I am calling some library function, and deep down, it is finally do something with that argument, and instead of manually finding where it is actually using that value, can i say, stop the code when the variable is accessed?

A: 

You can set breakpoints in Firebug.

RedFilter
This doesn't really answer his question
grepsedawk
You're right! The correct answer is, "yes".
RedFilter
It doesn't answer his question because he's not trying to stop on a particular line of code; he's trying to stop when a variable is accessed. Breakpoints alone won't help with this.
Dan Fabulich
Why not explain your answer OrbMan
Toby Allen
My answer was written before the question was edited to say he essentially does not want to set a manual breakpoint. I am saying that you can manually set a breakpoint with Firebug. If you want to modify your code to make things easier, Dan Fabulich's answer is a good approach,
RedFilter
A: 

I'm not aware of any way to do what you're asking, but can you try passing a value which is likely to break the library code? Then you'll get an exception and that can be seen in any JS debugger.

Alexander Shirshov
+1  A: 

Try defining a getter for your variable. A getter is a piece of code that runs whenever someone accesses an object's value. (This relatively new JavaScript feature is not available in IE, but if you're just using it for debugging in Firefox it should be fine.)

Your getter may simply return the value, but you can set a breakpoint in your getter. Or, even better, you can have the getter run the debugger statement to halt automatically.

Dan Fabulich
A: 

Dan Fabulich does have a more solid solution with the accessor method.

But I recently noticed that newer versions of Firebug have the ability to break on property changes. Find it in the DOM tabs.

dvdrtrgn

related questions