Is there a way to indicate un-needed parameters in arrow function arguments (and during destructuring as well)?
Contrived case in point where I am using _
to indicate un-need parameters in my arrow function:
import _ from 'lodash';
const m = [];
m.push({k: 1, v: 'a'});
m.push({k: 2, v: 'b'});
m.push({k: 3, v: 'c'});
const bExists = _.filter(m, ( {_,v}, _1, _2)=>{
return v==='b';
}).length > 0;
Two gripes with the above code:
_
(used in languages like F#) is the same as the lodash import. Not a syntax error but still confusingsubsequent
_
have to be renamed as_1
,_2
otherwise one gets:SyntaxError: es6/app.js: Argument name clash in strict mode
I could simply omit the _1
and _2
arguments but only because in this particular example the unneeded ones appear at the end of the argument list.
The first of the above gripes can obviously be solved by using some other name, yet the second one still stands (and whatever name is adopted as a convention would have to be mangled in subsequent unneeded arguments).
So, is there language support to indicate unused parameters in arrow functions or (failing that) established conventions on that?
Is there a way to indicate un-needed parameters in arrow function arguments (and during destructuring as well)?
Contrived case in point where I am using _
to indicate un-need parameters in my arrow function:
import _ from 'lodash';
const m = [];
m.push({k: 1, v: 'a'});
m.push({k: 2, v: 'b'});
m.push({k: 3, v: 'c'});
const bExists = _.filter(m, ( {_,v}, _1, _2)=>{
return v==='b';
}).length > 0;
Two gripes with the above code:
_
(used in languages like F#) is the same as the lodash import. Not a syntax error but still confusingsubsequent
_
have to be renamed as_1
,_2
otherwise one gets:SyntaxError: es6/app.js: Argument name clash in strict mode
I could simply omit the _1
and _2
arguments but only because in this particular example the unneeded ones appear at the end of the argument list.
The first of the above gripes can obviously be solved by using some other name, yet the second one still stands (and whatever name is adopted as a convention would have to be mangled in subsequent unneeded arguments).
So, is there language support to indicate unused parameters in arrow functions or (failing that) established conventions on that?
Share Improve this question asked Jun 15, 2016 at 9:42 Marcus Junius BrutusMarcus Junius Brutus 27.3k46 gold badges202 silver badges350 bronze badges 1- 2 "So, is there language support to indicate unused parameters in arrow functions" --- no – zerkms Commented Jun 15, 2016 at 9:46
1 Answer
Reset to default 6No, Javascript/ES6 don't support a syntax for unused arguments.
But yes there are conventions for that: Standard conventions for indicating a function argument is unused in JavaScript