26
Feb/08
0

Quick Tip, “Firebug breakpoints not breaking!”

When using FireBug to step through your JavaScript code in FireFox, sometimes it does not break on a line that you know is being executed. If you are like me you are like WTF, what is going on? I eventually realized that the reason FireBug was not breaking on some lines of my code was that the code I set my breakpoint on was inline and not inside a function. Apparently FireBug will not break on a line that is not inside a function. A quick fix for this is to wrap your code in a function and call the function immediately after declaring the function.

Instead of:

1
2
var foo = "stuff";
alert(foo);

Use:

1
2
3
4
5
function showFoo(){
    var foo = "stuff";
    alert(foo);
}
showFoo();

In the second block you can put breakpoints on either line inside the function showFoo() and FireBug will break when you expect it to.

For more on debugging JavaScript in Firefox check my Firebug post or my article on conditional break points.

[Post to Twitter]  [Post to Plurk]  [Post to Yahoo Buzz]  [Post to Delicious]  [Post to Digg]  [Post to Ping.fm]  [Post to Reddit]  [Post to StumbleUpon] 

Comments (0) Trackbacks (0)

No comments yet.

Sorry, the comment form is closed at this time.

No trackbacks yet.

Tweet This Post links powered by Tweet This v1.3.9, a WordPress plugin for Twitter.