最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - arrow functions: how to indicate un-needed parameters in destructuring - Stack Overflow

programmeradmin1浏览0评论

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?

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?

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
Add a ment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论