Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 386
gespinha Avatar asked Nov 04 '13 08:11

gespinha


1 Answers

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.

like image 168
Karl-Johan Sjögren Avatar answered Sep 21 '22 21:09

Karl-Johan Sjögren