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:


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

Use:


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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • DZone
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Technorati
  • Netvouz
  • Slashdot
  • blinkbits
  • blogmarks
  • Furl

This entry was posted on Tuesday, February 26th, 2008 at 10:54 pm and is filed under JavaScript, FireFox, Firebug, Debugging, programming, breakpoint. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Be the first to leave a comment.

Leave a Reply

You must be logged in to post a comment.

Bad Behavior has blocked 431 access attempts in the last 7 days.