TIL(oved): destructuring in Coffescript

I’ve talked about destructuring before on this blog, I think it’s a pretty useful langauge feature and use it where I can.

So today, I was writing a CSV importer which returns each row as an array like [thing1,thing2,thing3] so I started writing


processRow: (argsArray)->
	firstName = argsArray[0]
    lastName = argsArray[1]

when I had a thought, what if I could break the array elements into function arguments? I could do something janky like this

processRow: function(firstName, lastName,...){}

processRow.apply(this, row)

but just when I was going to do that I remembered coffeescript has destructuring which allows me to do:

processRow: ([firstName, lastName, ...])->

Which does the same thing as my first example. BAM!