Ter*_*rry 5 javascript jquery node.js backbone.js jshint
我有一个Node.js Web应用程序,我使用Backbone.js和jQuery.我的主要js文件是app.js包含所有必需脚本的地方,包括jQuery.所以,这是我的app.js代码的开头:
'use strict';
var _ = require('lodash');
var $ = require('jquery');
var B = require('backbone');
B.$ = $;
Run Code Online (Sandbox Code Playgroud)
现在如果我运行grunt我的项目,它会在jQuery加载到$的行引发错误.它告诉我这个:
Linting public/js/app.js ...ERROR
[L4:C5] W079: Redefinition of '$'.
var $ = require('jquery');
Run Code Online (Sandbox Code Playgroud)
我仍然可以运行所有内容grunt --force,但无论如何我想消除这个错误.有人可以解释为什么它会引发错误以及如何解决它?
我的.jshintrc档案:
{
"laxcomma": true
,"laxbreak": true
,"curly": true
,"eqeqeq": true
,"immed": true
,"latedef": true
,"newcap": true
,"noarg": true
,"sub": true
,"undef": true
,"unused": false
,"asi": true
,"boss": true
,"eqnull": true
,"node": true
,"browser": true
,"jquery": true
,"predef":
[
"suite"
,"test"
,"setup"
,"teardown"
,"suiteSetup"
,"suiteTeardown"
,"requestAnimationFrame"
]
}
Run Code Online (Sandbox Code Playgroud)
fms*_*msf 17
在jshint docs中:http://www.jshint.com/docs/options/
jquery = true
This option defines globals exposed by the jQuery JavaScript library.
Run Code Online (Sandbox Code Playgroud)
你告诉jshint jquery存在,因此他认为$是定义的.删除"jquery" : true",你的问题应该消失.