admin管理员组文章数量:1389768
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
本文标签: javascriptarrow functions how to indicate unneeded parameters in destructuringStack Overflow
版权声明:本文标题:javascript - arrow functions: how to indicate un-needed parameters in destructuring - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744699049a2620454.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论