简体   繁体   中英

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 structure 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();  
});

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(); });

as the error states , define the function first

function expandToggle() {
        //dosomething
}

then use it

$(document).ready(function() {
        expandToggle();  
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM