以下JS:
(function() {
"use strict";
$("#target").click(function(){
console.log("clicked");
});
}());
收益率:
test.js: line 5, col 3, '$' is not defined.
当使用JSHint 0.5.5检测时。什么好主意吗?
以下JS:
(function() {
"use strict";
$("#target").click(function(){
console.log("clicked");
});
}());
收益率:
test.js: line 5, col 3, '$' is not defined.
当使用JSHint 0.5.5检测时。什么好主意吗?
当前回答
还可以在.jshintrc中添加两行
"globals": {
"$": false,
"jQuery": false
}
这告诉jshint有两个全局变量。
其他回答
你所需要做的就是在.jshintrc中设置"jquery": true。
根据JSHint选项引用:
jquery 这个选项定义了由jQuery JavaScript库公开的全局变量。
你可能想做以下事情,
const $ = window.$
避免它抛出linting错误。
要修复使用在线JSHint实现时的此错误:
点击“CONFIGURE”(页面中栏顶部) 启用“jQuery”(在底部的“假设”部分下)
下面是一个可以放在.jshintrc中的小列表 随着时间的推移,我将在这个列表中添加新的内容。
{
// other settings...
// ENVIRONMENTS
// "browser": true, // Is in most configs by default
"node": true,
// others (e.g. yui, mootools, rhino, worker, etc.)
"globals": {
"$":false,
"jquery":false,
"angular":false
// other explicit global names to exclude
},
}
还可以在.jshintrc中添加两行
"globals": {
"$": false,
"jQuery": false
}
这告诉jshint有两个全局变量。