且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何调试Javascript应用程序?

更新时间:2022-10-21 10:32:20

对于JavaScript,大多数浏览器中的调试是一个阴性:



IE - 您真正需要调试的地方, F12 是控制台。您可以调用 console.log console.debug console.error 等等,它会打印出好的数据。当您在对象上调用 console.log 时,好的控制台将打印出对象的属性分解。还有一个主动的dom检查器,以便您可以看到脚本正在运行时发生了什么。




  • Firefox - 获取 Firebug插件。这是我最喜欢的控制台。我曾经梦想过的一切都需要,还有一些功能。

  • Chrome - 内置控制台,检查页面上的元素,以查看DOM的细分。 li>
  • Opera - 内置控制台

  • Safari - 添加 Firebug Lite 到页面,您将有一个JS驱动版本的Firebug。 Safari具有类似于Chrome的内置开发工具,但他们需要启用



对于所有浏览器,您可以添加 Firebug Lite ,但是我真的只用于IE和Safari。


I work in an application that is JavaScript intense. So to debug , I end up using many alerts. Are there other better ways to debug ? What methods do you use ?

For JavaScript, debugging is a sinch in most browsers:

IE - Where you really need to debug, F12 is the console. You can call console.log, console.debug, console.error and a few others, and it will print out good data. When you call console.log on an object, good consoles will print out the property break-down of the object. There's also an active dom inspector so that you can see what's going on as the script is running.

  • Firefox - Get the Firebug addon. It is my favorite console of them all. Does everything I've ever dreamed of needing, and a few more features.
  • Chrome - Built-in console, inspect element on the page to see the breakdown of the DOM live.
  • Opera - Built-in console
  • Safari - Add Firebug Lite to the page, and you'll have a JS driven version of Firebug. Safari has built-in dev tools similar to Chrome, however they need to be enabled.

For all browsers, you can add Firebug Lite, but I really only use it for IE and Safari.