我在文件remover.js中有以下对象:
'use strict';
(function( remover, $, undefined ) {
// ...
// Object's definition
// ...
}( window.remover = window.remover || {}, jQuery ));
Run Code Online (Sandbox Code Playgroud)
这用于外部文件main.js:
'use strict';
remover.doSomething();
Run Code Online (Sandbox Code Playgroud)
代码正在运行,但JSHint会引发以下问题:
Running "jshint:all" (jshint) task
app/scripts/stuff/main.js
line 3 col 1 'remover' is not defined.
? 1 problem
Run Code Online (Sandbox Code Playgroud)
如何删除此警告?
你有两种选择,一种是让乘坐的所有的不确定警告这是不利于你的调试,另外一个是专门解决全球实体问题.
禁用var undefined警告(坏!)
只需使用该选项禁用main.js文件上的警告undef
'use strict';
/*jshint undef:false */
Run Code Online (Sandbox Code Playgroud)告诉JSHint哪些是外部库(好!)
提到每个变量都是全局的
'use strict';
/*global remover */
Run Code Online (Sandbox Code Playgroud)现在运行grunt jshint应该输出:
Running "jshint:all" (jshint) task
? No problems
Run Code Online (Sandbox Code Playgroud)
有一个在部分的更多信息指令在JSHint文档.