gespinha
gespinha

Reputation: 8487

jsHint "myFunction is defined but never used"

I am reviewing my javascript with JsHint, and it always returns an error, saying that a function is never used. Well, this is not entirely true.

I am integrating my javascript on the project index by external link (<script src="myJs.js"></script>), and on the index I call the functions I have on the myJs.js file after the actual file link. So it all looks like this:

<script src="myJs.js"></script>
<script>
myFunction();
</script>

The reason why I call my functions on the actual document and not in the myJs.js file is because I need some PHP functions running in it, and I need to call them from my index file.

The problem here is that JsHint returns a harmful, but annoying error, saying that "myFunction is defined but never used". Is it not aware that my function can later be called within my index? How can I solve this? Should I simply ignore it?

Upvotes: 19

Views: 15718

Answers (1)

Karl-Johan Sj&#246;gren
Karl-Johan Sj&#246;gren

Reputation: 17532

At the top of myJs.js you could try adding an exported declaration with your function name, something like this.

/* exported myFunction */

This should silence your warning.

Upvotes: 30

Related Questions