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

JavascriptJslint

Javascript Problem Overview


> Possible Duplicate:
> JSLint: was used before it was defined

I run JSlint and saw errors like that:

'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.

How can I fix this error repoted by JSlint?

Javascript Solutions


Solution 1 - Javascript

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

/*global foo */

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichaelView Question on Stackoverflow
Solution 1 - JavascriptMatt BallView Answer on Stackoverflow