views:

934

answers:

2

I am currently debugging complex Javascript/AJAX code written with mootools with FireBug. I am looking for a way to stop the JS execution as if it was a breakpoint programmatically.

Ex:

instructions ...
degugger.breakpoint(); // the execution stops here as if a breakpoint was
                       // manually set
other instructions ...

any idea?

+17  A: 

In Firefox, IE, Safari and Chrome (not Opera) you can set the debugger directive.

// your JS code
...
// break here
debugger;

This is extremely useful with Firebug.

RaYell
This works in IE as well.
vit
It will also work with IE if you enable Script Debugging in the Internet Options.
Kirtan
Works in Safari and Chrome as well, doesn't work on Opera.
RaYell
After you have done this, you should be then be able to use breakpoints in your IDE debugger. This saves you from having to declare multiple 'debugger;' lines of code across your application.
James Wiseman
+2  A: 

you can debug using firebug just open the script tab and blick on the line where you want the execution to stop

Niko