问题描述
在我的项目中,我们有一些作为容器的全局变量:
In my project we have some global variables that work as containers:
MyProject.MyFreature.someFunction = function() { ... }
然后我在整个网站中使用该脚本,JSLint / JSHint抱怨:
So then I use that script across the site and JSLint / JSHint complains about that:
我知道我可以访问每个JavaScript文件并在其上添加注释 / *全局MyProject * /
。但我正在寻找一种在某种配置文件中定义该注释的方法,因此我不必通过添加此注释的文件去文件。
I know that I can go to every JavaScript file and add the comment /*global MyProject*/
on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment.
某种在 config / jshint.yml
中的选项会很好。
Some kind on option in the config/jshint.yml
would be nice.
推荐答案
对于JSHint,您可以使用
For JSHint you can create .jshintrc
to your project directory with
{
"globals": { "MyProject": true }
}
这篇关于如何告诉JSLint / JSHint已经定义了全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!