我有一个使用Backbone.js和jQuery的Node.js Web应用程序。我的主要js文件是app.js
包含所有必需脚本(包括jQuery)的位置。因此,这是我的app.js代码的开始:
'use strict';
var _ = require('lodash');
var $ = require('jquery');
var B = require('backbone');
B.$ = $;
现在,如果我grunt
在我的项目上运行,它将在jQuery加载到$的行上引发错误。它向我显示了这个:
Linting public/js/app.js ...ERROR
[L4:C5] W079: Redefinition of '$'.
var $ = require('jquery');
我仍然可以使用运行所有内容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"
]
}
在jshint docs中:http : //www.jshint.com/docs/options/
jquery = true
This option defines globals exposed by the jQuery JavaScript library.
您正在告诉jshint jQuery存在,因此他假设$已定义。删除"jquery" : true"
,您的问题就会消失。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句