Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint: Use a named parameter

Tags:

jquery

jslint

So I'm running JSLint on the lastest version of jQuery available at bit.ly/jqsource. I've made the tests as lax as possible, but I still get errors. One of them is "Use a named parameter" on line 327:

target = arguments[0] || {},

What does it mean? Even this blog post doens't provide information.

like image 409
Randomblue Avatar asked Feb 23 '23 05:02

Randomblue


2 Answers

It means that the code is accessing the parameter using the arguments collection instead of a parameter specified in the function signature:

You can reproduce the error message with this code:

function x(a) {
    var b = arguments[0];
}

Using the named parameter gives the same result without the lint error:

function x(a) {
    var b = a;
}
like image 88
Guffa Avatar answered Feb 25 '23 19:02

Guffa


I'll assume it actually says "Use a named parameter" instead of "variable".

If so, there can be a performance hit in some browsers when you reference the arguments object. I'd guess that's what it's complaining about.

Some browsers will optimize away the creation of the arguments object if it is never referenced.

like image 40
user113716 Avatar answered Feb 25 '23 19:02

user113716