8

Can I pause execution from within JS code? I am working on a simple haxe-based debug util, and I want to be able to simulate breakpoints, by calling a util method which will trigger the execution pause.

1 Answer 1

17

Not sure if this is what you're looking for, but in Chrome (and Firefox if Firebug is installed) you can use the built-in JavaScript debugger statement. This causes the execution to pause, and is effectively like setting a breakpoint. For example, the following would break on every iteration of the loop allowing you to examine the value of i (stupidly simple example):

for(var i = 0; i < 10; i++) {
    debugger;
    console.log(i);
}
Sign up to request clarification or add additional context in comments.

2 Comments

In Haxe, this can be done untyped __js__('debugger'); Hopefully for haxe 3 we can add a simple function, such as js.Lib.debugger();
Pretty cool. Now if there was a keyboard shortcut that could inject the debugger statement into the console, that would be amazing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.