Javascript warning: "Function X is used before it is declared"
Functions can be defined in two ways:
function foo() {}
and
var foo = function() {};
The warning "Function X is used before it is declared" is only valid for the second format.
The first version should not cause this warning, since it is "hoisted" within the scope it is in.
Please sign in to leave a comment.
This is quite typical for a linter to catch. Despite the hoisting, it's still considered by many to be bad practice. I've never personally had an issue with it though, and like to leverage the hoisting of functions to organize my code (i.e. I put all my function definitions at the bottom of the file).
However, if you want to disable this inspection, there are at least two different ways:
Notice that this setting only applies to functions. Variables being used before they're defined will still show the warning (as they should).
It seems to me that setting is the same as jshint/jslint's latedef: "nofunc" option. ReSharper just made it less conventional to configure. It would be nice if they just used an existing .jshintrc file instead.
Hope that helps!
Agree with Glen.
This message should not be shown for the functions declared as `function X(){...}`.
I think this should be posted as a bug of R#.