[英]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. 我是jQuery的新手,并且正在jsFiddle上使用jsLint来测试代码段中是否存在错误。 Below is the structure of the code I am using but jsLint shows that my function expandToggle()
was used before it was defined: 以下是我正在使用的代码的结构,但是jsLint显示我的函数expandToggle()
在定义之前就已使用:
$(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. 为了使jsLint冷静下来,请切换代码。
function expandToggle() {
//dosomething
}
$(document).ready(function() {
expandToggle();
});
It means this: 这意味着:
$(document).ready(function() { expandToggle(); }); $(document).ready(function(){ expandToggle(); });
Was before this: 在此之前:
function expandToggle() { //dosomething } 函数expandToggle(){//做某事}
To fix just rearrange them: 要解决此问题,只需重新排列它们:
function expandToggle() { //dosomething } 函数expandToggle(){//做某事}
$(document).ready(function() { expandToggle(); }); $(document).ready(function(){expandToggle();});
as the error states , define the function first 作为错误状态,请首先定义功能
function expandToggle() {
//dosomething
}
then use it 然后用它
$(document).ready(function() {
expandToggle();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.