简体   繁体   English

你如何调试Javascript应用程序?

[英]How do you debug Javascript applications?

I work in an application that is JavaScript intense. 我在一个JavaScript强大的应用程序中工作。 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: 对于JavaScript,调试在大多数浏览器中都是一个难题:

IE - Where you really need to debug, F12 is the console. IE - 你真正需要调试的地方, F12是控制台。 You can call console.log , console.debug , console.error and a few others, and it will print out good data. 你可以调用console.logconsole.debugconsole.error和其他一些,它会打印出好的数据。 When you call console.log on an object, good consoles will print out the property break-down of the object. 当您在对象上调用console.log时,良好的控制台将打印出对象的属性细分。 There's also an active dom inspector so that you can see what's going on as the script is running. 还有一个活跃的dom检查器,以便您可以看到脚本运行时发生了什么。

  • Firefox - Get the Firebug addon . Firefox - 获取Firebug插件 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. Chrome - 内置控制台,在页面上检查元素以查看DOM直播的细分。
  • Opera - Built-in console Opera - 内置控制台
  • Safari - 苹果浏览器 - Add Firebug Lite to the page, and you'll have a JS driven version of Firebug. Firebug Lite添加到页面中,您将拥有一个JS驱动版本的Firebug。 Safari has built-in dev tools similar to Chrome, however they need to be enabled . Safari具有类似于Chrome的内置开发工具,但需要启用它们

For all browsers, you can add Firebug Lite , but I really only use it for IE and Safari. 对于所有浏览器,您可以添加Firebug Lite ,但我实际上只将它用于IE和Safari。

Most modern browsers include a console, which can help with displaying syntax errors and the like. 大多数现代浏览器都包含一个控制台,它可以帮助显示语法错误等。 Of course, there's Firebug . 当然,还有Firebug

Use Firefox as your main development platform and open the Web Console. 使用Firefox作为主要开发平台并打开Web控制台。 Error messages are printed there. 在那里打印错误消息。

Chrome also has a console, but it doesn't have Firebug, a Firefox add-on used for web development. Chrome还有一个控制台,但它没有Firebug,一个用于Web开发的Firefox插件。 While the Web Console that comes with Firefox will display errors in Javascript, Firebug will also help with inspecting the HTML for your page, and there are even extensions to Firebug like Flashbug for working with Flash components on your page. 虽然Firefox附带的Web控制台将在Javascript中显示错误,但Firebug也可以帮助检查页面的HTML,甚至还有Firebug的扩展,如Flashbug,用于处理页面上的Flash组件。

Obviously you'll want to check your web apps in all browsers eventually, but do most of your developing in Firefox. 显然,您最终会想要在所有浏览器中检查您的网络应用程序,但是在Firefox中进行大部分开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM