Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for unused function parameters

I have been wondering what the best method is to deal with the following.

someCallback: function(param1,param2,paramThatIActuallyNeed) {
     doSomethingWith(paramThatIActuallyNeed)
}

So in this example, param1 and param2 are unused, however I need to place them there in order to access that third parameter. This makes JSLint sad and I'm wondering what the practice is to avoid this? This tends to happen when using libraries with many callback results.

like image 769
Rob Avatar asked Aug 30 '26 07:08

Rob


2 Answers

That is what unparam is for:

/*jslint unparam: true */

This is another good reason to prefer jshint, which does not engage in such stupidity.

I would definitely advise against using arguments just to appease jslint.

You can use the arguments object, detailed here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments

Ex:

someCallback: function() {
     doSomethingWith(arguments[2]);
}
like image 34
Enzo Avatar answered Aug 31 '26 21:08

Enzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!