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
How to fix "foo is not defined" error reported by JSlint?
提问by Michael
Possible Duplicate:
JSLint: was used before it was defined
可能的重复:
JSLint:在定义之前使用过
I run JSlint
and saw errors like that:
我运行JSlint
并看到了这样的错误:
'foo' is not defined. var x = foo();
foo
is a function defined in another JavaScript
file foo.js
. As I understand there is no "import / require" directives in JavaScript
to reference the foo
function 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 */