Telling Firebug to Break as Soon as any Javascript is Executed

前端 未结 5 2137
情书的邮戳
情书的邮戳 2021-02-04 11:00

I\'ve inherited a pile of code that\'s doing unexpected things when I click on some

5条回答
  •  眼角桃花
    2021-02-04 11:10

    If this is a generic debugging problem you can use the Web Inspector in Safari / Chrome. An added bonus is that you can throw the following statement into your JavaScript code to pull up the debugger:

    ...
    debugger; // Will trigger the debugger
    ...
    

    Otherwise you can set breakpoints, conditional breakpoints, pause on the next execution, and all the usual tricks. Some nice videos are available here.

    In response to the alert suggestion before. I would seriously recommend using console.log or console.dir if you have access to a debugger. You will get more information without blocking your script's execution. Also, don't forget that that console.log can take multiple parameters so you can nicely print out data, you don't have to constrain yourself to a single string like alert.

提交回复
热议问题