admin管理员组文章数量:1314496
I have the following code:
var $form = $modal.find('#main-form');
var $submitBt = $modal.find('.block-footer button:contains("Submit")');
var oSubmit = {
$form: $form,
$modal: $modal,
action: $form.attr('data-action'),
entity: $form.attr('data-entity'),
href: $form.attr('data-href'),
row: $link.attr('data-row'),
$row: $('#row_' + $link.attr('data-row')),
$submitBt: $submitBt
};
When I used jslint it told me three things:
- Missing
'use strict'
statement. - Combine this with the previous 'var' statement.
<-
many of these $row: $('#row_' + $link.attr('data-row'))
- error: '$' was used before it was defined.
Can someone give me some advice on what's normal practice with these messages.
I have the following code:
var $form = $modal.find('#main-form');
var $submitBt = $modal.find('.block-footer button:contains("Submit")');
var oSubmit = {
$form: $form,
$modal: $modal,
action: $form.attr('data-action'),
entity: $form.attr('data-entity'),
href: $form.attr('data-href'),
row: $link.attr('data-row'),
$row: $('#row_' + $link.attr('data-row')),
$submitBt: $submitBt
};
When I used jslint it told me three things:
- Missing
'use strict'
statement. - Combine this with the previous 'var' statement.
<-
many of these $row: $('#row_' + $link.attr('data-row'))
- error: '$' was used before it was defined.
Can someone give me some advice on what's normal practice with these messages.
Share Improve this question edited Sep 17, 2012 at 11:41 fresskoma 25.8k12 gold badges86 silver badges131 bronze badges asked Sep 17, 2012 at 11:21 user1464139user14641394 Answers
Reset to default 7Regarding
use strict
, take a look at strict mode. It is an opt-in feature, so it is not an error.This is simply a matter of taste. JSLint propose that you write:
var foo, bar, baz;
instead of
var foo; var bar; var baz;
This is because JSLint doesn't know about jQuery (and its "$" variable), so it thinks you are using undefined variables. You may put a
/* global $ */
at the top of your JS file, or type$
into the textare that says predefine global variables here (thanks Fabrício Matté)
Also, regarding JSLint in general:
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.
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.
Source (foxxtrot)
They are just messages, not errors. You can easily switch them off and/or ignore them.
1) is more a tip than a "missing statement".
2) is a code style hint. You may write:
var $form = …,
$submitBt = …,
oSubmit = …;
3) seems like a unusual inclusion of jQuery (did you redeclare it?), or that jslint missed the global variable.
1) use strict
: This basically makes you write better JavaScript. It prevents you from using some of the "bad" features in JavaScript.
2) Combine var
: Don't worry about this one, it's just a style preference.
3) $
was used before it was defined: it's just informing you that $
doesn't exist. You have to add it to the jsLint global variables.
You can disable any of these options within jsLint by putting the options at the start of your JS file:
/*jslint options */
More info at http://www.jslint./lint.html
- Add
"use strict";
to the start to the function. - Declare the variables using one
var
statement:var foo = b, bar = d
, etc. - Add
/*global $: false */
to the start of the file. This will tell JSLint that there exists a global variable called $ which the script can use.
本文标签: javascriptHow do I deal with JSLint errors and warningsStack Overflow
版权声明:本文标题:javascript - How do I deal with JSLint errors and warnings? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741967100a2407613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论