문제

Pretty simple question, but much to my surprise I could not find an answer on the internets.

In PHP we have exit; which will simply stops executing any further code when it reaches that line, assuming there are no errors.

Does jQuery (JAVASCRIPT for all yous) have a similar built in function? This is to be used for debugging, not for production.

Thanks!

도움이 되었습니까?

해결책

window.stop() (vanilla JavaScript, not jQuery) would simulate the user clicking the Stop button on the browser, preventing the browser from downloading and rendering the current page.

다른 팁

First, a pet peeve: there's no such language as jQuery. That's just a library framework on top of JavaScript. The question is presumably whether JavaScript has an exit function.

If you want to stop script execution, and you're in a debug environment, you have a few options, none of which are exit:

  • You can pop up an alert. This will stop execution, but doesn't let you do much.
  • You can use the debugger; statement. This may be what you want - just put it in a line, and if your console is open, it will bring up the debugger at that point.

The last alternative will work, but isn't pretty. Simply throw an exception (or cause one of your own, e.g. myNonExistantVariable.thereIsNoProperty.soExceptionWillHappen = 0;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top