开发者

jsLint shows "somefunction() was used before it was defined" error

开发者 https://www.devze.com 2023-03-31 14:24 出处:网络
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 expand

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号