I have the following code which in it's simplest form consists of calling a function when the DOM is fully loaded. I am using a function declaration so that I can call myFunction
both before and after it is defined.
/*global $*/
$(function() {
"use strict";
myFunction();
function myFunction() {
// do something
}
});
If the function is called before the declaration then JSLint gives the following error:
'myFunction' is out of scope.
If I put the function declaration before I call the function then JSLint gives no errors. However this defeats the whole point of using a function declaration (being able to call the function before and after the definition.
/*global $*/
$(function() {
"use strict";
function myFunction() {
// do something
}
myFunction();
});
Can someone explain why this is the case? I think I have an understanding about what out of scope means for variables but I don't understand how this applies to function declarations.