jsLint shows "somefunction() was used before it was defined" error
I am new to jQuery and I am using jsLint on jsFiddle to test if I have errors on my code snippets. Below is the st开发者_运维百科ructure of the code I am using but jsLint shows that my function expandToggle()
was used before it was defined:
$(document).ready(function() {
expandToggle();
});
function expandToggle() {
//dosomething
}
Can someone help me what this error means?
It means what it says. To make jsLint calm down switch your code around.
function expandToggle() {
//dosomething
}
$(document).ready(function() {
expandToggle();
});
as the error states , define the function first
function expandToggle() {
//dosomething
}
then use it
$(document).ready(function() {
expandToggle();
});
It means this:
$(document).ready(function() { expandToggle(); });
Was before this:
function expandToggle() { //dosomething }
To fix just rearrange them:
function expandToggle() { //dosomething }
$(document).ready(function() { expandToggle(); });
精彩评论