JSLint: Using a function before it's defined error

Solution 1:

As this is the top rated google hit and other people might not be seeing it at first in the jslint tool, there is a option called "Tolerate misordered definitions" that allows you to hide this type of error.

/*jslint latedef:false*/

Solution 2:

If you declare functions using the function keyword, you can use them before they're declared. However, if you declare a function via another method (such as using a function expression or the Function constructor), you have to declare the function before you use it. See this page on the Mozilla Developer Network for more information.

Assuming you declare all your functions with the function keyword, I think it becomes a programming-style question. Personally, I prefer to structure my functions in a way that seems logical and makes the code as readable as possible. For example, like you, I'd put an init function at the top, because it's where everything starts from.

Solution 3:

If you're using jshint you can set latedef to nofunc, which will ignore late function definitions only.

Documentation - http://www.jshint.com/docs/options/#latedef

Example usage:

/* jshint latedef:nofunc */

noop();

function noop() {}

Hope this helps.