如何在java脚本代码中发现拼写错误 [英] How to spot spelling errors in java script code

查看:155
本文介绍了如何在java脚本代码中发现拼写错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个主要使用Angular,Gridster,jQuery和其他一些JavaScript文件的Web应用程序。最常见的错误是在键入特定语法时拼写错误,并且这些语法错误未在FireBug或任何其他开发人员工具中显示。有任何建议如何以结构化的方式调试这个并找出问题吗?



我尝试过:



我找不到使用Visual Studio或Fire bug等开发工具调试的任何解决方案,

解决方案

< blockquote>检查这个



JSHint,一个JavaScript代码质量工具 [ ^ ]

Javascript Online Lint [ ^ ]


这个问题对我来说似乎很棘手。这个问题并不比所有其他脚本语言的类似问题困难,但实际上要容易得多,因为它因为其独特的特性和高需求而受到很多人的关注。



使用Visual Studio不早于2013年(即2013年或2015年):其Intellisense已得到极大改进;很高兴与我合作。如果您使用的是不同的平台,请尝试使用MonoDevelop和/或SharpDevelop;我有一段时间没有尝试过它们,但检查它们是否也改进了Intellisense。



比以往更频繁地使用调试器;它会很快检测到与拼写相关的随机错误。在try-catch块下开发代码,提供特殊的异常信息。不幸的是,你不能以这种方式发现词汇错误(请参阅我关于这个主题的文章章节: 处理词法错误 ),但调试器会。在开发过程中,您可以对所有异常信息进行特殊的非常详细的转储,稍后您可以修改或删除。



调试器检测到的拼写错误的常见效果很简单。比如说,你有对象 A 并创建一些属性 A.MyProperty 。如果您稍后尝试读取此属性但拼错它,则该对象(例如 A.MyProperti )将被分配给特殊的 undefined object(原始值)。如果整个变量拼写错误,那么它也将是 undefined 。这很容易检测到。请参阅:

undefined - JavaScript | MDN



您可以使用Visual Studio调试器或其他一些调试器。 Visual Studio调试器是我最喜欢的,但不幸的是,据我所知,它需要IE(也许是Edge,我也不确定),我认为这是不可接受的,并且大部分时间都处于禁用状态。因此,我必须使用其他一些调试器;我使用Chrome。到目前为止,这不是那么舒服,但仍然是全面的。此外,它在体面的浏览器下执行调试。 (我不认为IE是一个真正的浏览器。)



是的,你不能像编译语言那样达到拼写检测的便利,但是解释性的工作方法语言正在接近JavaScript的最佳状态。



-SA


I am developing a web application primarily using Angular, Gridster, jQuery and few other JavaScript files. The most common error is spelling mistake while typing a particular syntax and these syntax errors are not shown in FireBug or any other developer tools. Any suggestion how to debug this in a structured way and find out the issue(s)?

What I have tried:

I couldn't find any solution using debug of the development tools like Visual Studio or Fire bug etc.,

解决方案

Check this

JSHint, a JavaScript Code Quality Tool[^]
Javascript Online Lint[^]


The problem seems artificial to me. This problem is not harder than the similar problem with all other scripting languages, but is actually much easier, due to a lot of attention paid for JavaScript, due its unique character and high demand.

Use Visual Studio not earlier than 2013 (that is, 2013 or 2015): its Intellisense has been greatly improved; pleasure to work with. If you are using different platforms, try MonoDevelop and/or SharpDevelop; I haven't try them for a while, but check if they also improved Intellisense.

Use the debugger more often than you used to; it will quickly detect random mistakes like related to spelling. Develop code under the try-catch block providing special exception information. Unfortunately, you cannot catch lexical mistakes this way (please see the chapter of my article on this topic: Handling Lexical Errors), but the debugger will. During development, you can do special very detailed dump of all exception information, which you later can modify or remove.

The usual effect of misspelling detected by a debugger is simple. Say, you have the object A and create some property A.MyProperty. If you later try to read this property but misspell it, the object, say, A.MyProperti will be assigned to a special undefined object (primitive value). If a whole variable is misspelled, it will be undefined, too. This is easy to detect. Please see:
undefined — JavaScript | MDN.

You can use Visual Studio debugger, or some other debugger. Visual Studio debugger is the best to my taste, but unfortunately it requires, to best of my knowledge, IE (maybe Edge, too, I'm not sure), which I consider unacceptable and keep disabled most of the time. Therefore, I have to use some other debugger; and I use Chrome. It is, by far, not so comfortable, but still comprehensive. Besides, it performs the debugging under the decent browser. (I don't consider IE a real browser.)

Yes, you cannot reach the convenience in spelling detection as in compiled language, but the methods of work with interpretive languages is approaching the optimum possible for JavaScript.

—SA


这篇关于如何在java脚本代码中发现拼写错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆