Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint error "Unexpected Var" [closed]

JSLint keeps giving me the following error whenever defining 2 functions:

Problem at line __ character _: Unexpected 'var'.

I have tried declaring all vars at the beginning of the script but this does not solve the issue. Tried digging through the web for an answer but cannot seem to find one.

var walk = function walker(node, func) {
    //code
}

var disp= function display(){
    //code
    return d;
}
like image 651
user1243918 Avatar asked Mar 01 '12 23:03

user1243918


1 Answers

Try declaring them like this:

var walker = function (node, func) {
    //code
};
var display = function () {
    //code
    return d;
};

The problem with:

var walk = function walker(node, func) {
    //code
};

is JSLint expects walk to be either assigned a function or the result of the function. If you want to assign a function to the variable, the variable name becomes an alias of the function. To make JSLint happy, it should be an anonymous function.

like image 168
pete Avatar answered Oct 23 '22 09:10

pete