How to return couple values in iced coffee script
using return
and autocb
?
Without autocb
I can do:
func = (cb)=>
cb returnVal1, returnVal2
How to implement this using autocb
? This code ...
func = (autocb)=>
return returnVal1, returnVal2
... throws error:
SyntaxError: unexpected ,
You are getting an error because you can't return more than one value in JavaScript. You could wrap the two values in an array and destructure it after calling...
func = (autocb)=>
return [returnVal1, returnVal2]
await func defer(returnVals)
[returnVal1, returnVal2] = returnVals
...but you should probably just use your first example. autocb
is simple syntactical sugar (one argument instead of one line), and not at all necessary to using IcedCoffeeScript.