如果jQuery未通过验证,JSLint有什么用处 [英] What good is JSLint if jQuery fails the validation

查看:138
本文介绍了如果jQuery未通过验证,JSLint有什么用处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在探索清理和测试JavaScript的不同方法。我认为就像任何其他语言一样,改善的一种方法就是阅读好的代码。 jQuery非常受欢迎,所以它必须具有一定程度的良好编码。

So I have been exploring different methods to clean up and test my JavaScript. I figured just like any other language one way to get better is to read good code. jQuery is very popular so it must have a certain degree of good coding.

那么为什么当我通过JSLint的验证运行jQuery时它会给我这样的信息:

So why when I run jQuery through JSLint's validation it gives me this message:


错误:

Error:

第18行问题5:
预期标识符,而是看到
'undefined'(保留字)。

Problem at line 18 character 5: Expected an identifier and instead saw 'undefined' (a reserved word).

未定义,

第24行问题27:
缺少分号。

Problem at line 24 character 27: Missing semicolon.

jQuery = window.jQuery = window。$ =
函数(选择器,上下文){

jQuery = window.jQuery = window.$ = function( selector, context ) {

第24行的问题字符28:
预期标识符,而是看到
'='。

Problem at line 24 character 28: Expected an identifier and instead saw '='.

jQuery = window.jQuery = window。$ =
函数(选择器,上下文){

jQuery = window.jQuery = window.$ = function( selector, context ) {

第24行问题28:
停止,无法继续。 (已扫描0%

Problem at line 24 character 28: Stopping, unable to continue. (0% scanned).

这是使用 JSLint jquery-1.3.1.js

推荐答案

JSLint测试一个特定的人(Douglas Crockford)关于什么的意见制作好的JavaScript代码。 Crockford非常好,但他的一些观点充其量只是肛门保留,如下划线规则,或使用增量/减量运算符。

JSLint tests one particular person's (Douglas Crockford) opinions regarding what makes good JavaScript code. Crockford is very good, but some of his opinions are anal retentive at best, like the underscore rule, or the use of the increment/decrement operators.

许多问题在上面的输出中被JSLint标记的是Crockford认为导致难以维护的代码的问题,或者他认为这些问题导致他过去做了一些难以维护的聪明事情。

Many of the issues being tagged by JSLint in the above output are issues that Crockford feels leads to difficult to maintain code, or they are things that he feels has led him to doing 'clever' things in the past that can be hard to maintain.

有些东西Crockford认为是我同意的错误,比如丢失的分号。删除分号会强制浏览器猜测插入语句结束标记的位置,这有时会很危险(它总是较慢)。其中一些错误与JSLint有关,而不是期望或支持jQuery在第24行上执行的多个赋值。

There are some things Crockford identifies as errors that I agree with though, like the missing semicolons thing. Dropping semicolons forces the browser to guess where to insert the end-of-statement token, and that can sometimes be dangerous (it's always slower). And several of those errors are related to JSLint not expecting or supporting multiple assignments like jQuery does on line 24.

如果您对JSLint错误有疑问,请参阅-mail Crockford,他非常善于回复,而且他的回复,你至少知道为什么JSLint会以这种方式实现。

If you've got a question about a JSLint error, e-mail Crockford, he's really good about replying, and with his reply, you'll at least know why JSLint was implemented that way.

哦,只是因为一个库很流行并不意味着它的代码是好的。 JQuery很受欢迎,因为它是一个相对快速,易于使用的库。它实施得很好,在很多人中很受欢迎。但是,您当然应该阅读更多代码,我们都应该这样做。

Oh, and just because a library is popular doesn't mean it's code is any good. JQuery is popular because it's a relatively fast, easy to use library. That it's well implemented is rather inconsequential to it's popularity among many. However, you should certainly be reading more code, we all should.

JSLint可以非常有助于识别代码问题,即使JQuery没有通过标准它的愿望。

JSLint can be very helpful in identifying problems with the code, even if JQuery doesn't pass the standards it desires.

这篇关于如果jQuery未通过验证,JSLint有什么用处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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