Javascript 如何修复 JSlint 报告的“foo is not defined”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11957977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:49:03  来源:igfitidea点击:

How to fix "foo is not defined" error reported by JSlint?

javascriptjslint

提问by Michael

Possible Duplicate:
JSLint: was used before it was defined

可能的重复:
JSLint:在定义之前使用过

I run JSlintand saw errors like that:

我运行JSlint并看到了这样的错误:

'foo' is not defined.
var x = foo();

foois a function defined in another JavaScriptfile foo.js. As I understand there is no "import / require" directives in JavaScriptto reference the foofunction defined in another source file.

foo是另一个JavaScript文件中定义的函数foo.js。据我了解,没有“导入/要求”指令JavaScript来引用foo另一个源文件中定义的函数。

How can I fix this error repoted by JSlint?

我怎样才能解决这个错误报告JSlint

回答by Matt Ball

Use the global directive to tell JSLint about foo's assumed existence.

使用 global 指令告诉 JSLint 关于foo的假定存在。

/*global foo */

http://www.jslint.com/help.html#global

http://www.jslint.com/help.html#global