I have a reduce function like this:
ops = rqOps.reduce (p, { commit: id: cid, type: type }, idx, arr) ->
# Do stuff here
p
, {}
which works fine, but now the name of the second argument compiles to _arg
. How can I give it a different name? I've tried several different approaches like arg = { commit: id: cid, type: type }
and { commit: id: cid, type: type } : arg
and { commit: id: cid, type: type } = arg
but nothing compiles to the intended result. What's wrong with my syntax?
Why do you care what the second argument is called? Your object destructuring means that you wouldn't work with that argument at all, you'd just work with
cid
andtype
instead. The_arg
name and even its existence is subject to change and none of your business.For example, if you have this:
then you'll get
1, 2
and2, 3
in the console. If you want the whole second argument then give it a name and unpack it inside the iterator function: