3

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:

  1. _ (used in languages like F#) is the same as the lodash import. Not a syntax error but still confusing
  2. subsequent _ 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?

Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331

1 Answers1

6

No, 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

Community
  • 1
  • 1
Dario
  • 3,905
  • 2
  • 13
  • 27