Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return object explicitly in CoffeeScript

Tags:

coffeescript

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?

like image 558
Alice Avatar asked Feb 05 '11 15:02

Alice


People also ask

How do you define a function in CoffeeScript?

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 (->).


1 Answers

myFunc = ->   return {     id   : 3     name : 'myname'   }  myFunc = ->   return {} =     id   : 3     name : 'myname'  myFunc = ->   # return   id   : 3   name : 'myname' 
like image 102
matyr Avatar answered Sep 20 '22 01:09

matyr