Non-binding destructuring assignment
Tab Atkins Jr.
jackalmage at gmail.com
Wed Apr 29 16:54:16 UTC 2015
On Wed, Apr 29, 2015 at 4:39 AM, Elie Rotenberg <elie at rotenberg.io> wrote:
> Using array destructuring assignment and constraining linting rules, I often
> find myself having to chose names for bindings I don't intent on using. I
> usually end up using a conventional ignore name, such as _ignore, which I
> "void" to shut up the linter without adding exceptions. Besides the linting
> problem (which can be solved by refining the linting rules), it's still a
> conceptually useless binding.
>
> Here's a contrived example:
>
> const lastOfThree = ([first, second, third]) => third;
>
> Which I usually end up rewriting:
>
> const lastOfThree = ([_ignore1, _ignore2, third]) => {
> void _ignore1;
> void _ignore2;
> return third;
> }
Honestly, this should probably be answered by fixing the linter, so it
doesn't give linting errors when a variable named "_" is unused. (In
fact, it should probably do the opposite, and give a lint error when _
*is* used. This'll make users of underscore or lo-dash unhappy,
though. ^_^)
~TJ
More information about the es-discuss
mailing list