re: Here's a super-quick JavaScript trick for omitting argument names. VIEW POST

FULL DISCUSSION
 

What's the use case for this? I don't see why you'd have an argument to a function that you never use in the function. Why not just remove the unused argument?

 

The use case is probably in something more FP-related, such as in the .map example I gave in my article. In those cases you don't choose the arguments being passed to your function.

 

Oh, that's very true. In the map callback you may be interested only in the index, not the actual value, so you would use that trick in that instance. Got it, thanks!

My pleasure!

One thing to note is that I don't think I'll be using this in every situation... it's definitely a tradeoff in familiarity for "conciseness", but then again, so is using !0 instead of true. However, it is something that quite neatly uses quite a few recently introduced JavaScript features / sugars, so I thought it would be pretty cool to talk about. :)

 

I guess sometimes the shape of the arguments used to call your function are out of your control - e.g. event handlers; callbacks from other libraries etc. - and there may be times when you don't need all the arguments exposed in your function body. In which case you either define a parameter you don't use; or do this...

code of conduct - report abuse