Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!

Expected parameter (value) in set '{a}' function

When do I get this error?

JSLint will throw the "Expected parameter (value) in set '{a}' function" error when it encounters multiple named arguments in the signature of a property setter function, none of which have the identifier value. In the following example we create an object x with a getter and setter. The getter will always return half of the set value (since getters and setters are an ECMAScript 5 feature we need to set the es5 option, otherwise JSLint will not recognise them):

Why do I get this error?

This error is raised to highlight a lack of convention and a completely pointless piece of code. Your code will run without error if you do not change it, but could be confusing to other developers and adds unnecessary bytes to the weight of your script.

ECMAScript 5 added new syntax for object property getter and setter functions. The specification states the following in reference to getters (ES5 §8.6.1):

The function’s [[Call]] internal method... is called with an arguments list containing the assigned value as its sole argument each time a set access of the property is performed.

Since the runtime will only ever pass a single argument to the function, there is no need to provide more than one named argument in the function signature. By convention, this single argument should be named value, since it will be used to set the value of something. To fix this error, simply remove any additional named arguments, and rename the first one to value:

James Allardice

This article was written by James Allardice, an enthusiastic young JavaScript developer at Global Personals (we're looking for developers so please apply). He is passionate about writing clean, maintainable JavaScript and uses JSHint every day to help achieve this.

You can follow him on Twitter, fork him on GitHub and find him on Google+.

Proceeds generated by this site are donated to help advance other open source projects

comments powered by Disqus