我有一个 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.$ = $;
现在,如果我在我的项目上运行 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 文档中:http://www.jshint.com/docs/options/
jquery = true
This option defines globals exposed by the jQuery JavaScript library.
您告诉 jshint jquery 存在,因此他假设 $ 已定义。删除 "jquery": true"
,您的问题应该会消失。
关于javascript - jshint 错误 : Redefinition of '$' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24510773/