This works:
myfunc = () -> id: 3 name: 'myname'
But I want to be explicit about returning object.
myfunc = () -> return id: 3 name: 'myname'
But I get "Unexpected 'INDENT'" error. What's wrong with the above code?
The syntax of function in CoffeeScript is simpler as compared to JavaScript. In CoffeeScript, we define only function expressions. The function keyword is eliminated in CoffeeScript. To define a function here, we have to use a thin arrow (->).
myFunc = -> return { id : 3 name : 'myname' } myFunc = -> return {} = id : 3 name : 'myname' myFunc = -> # return id : 3 name : 'myname'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With