I’m trying to wrap my head around the Coffeescript syntax. I had a question about something I saw while looking through some source code. Basically, the author defined a class, and then added two functions inside the class, but for one of the functions he used parentheses, but did not use parentheses for the second function. The code can be found here:
class BackboneApp
constructor: () ->
@events = _.extend({}, Backbone.Events)
@fetchUserInfo()
start: ->
Backbone.history.start
root: '/chatty'
@events.trigger 'start', ''
Why are parentheses used for constructor, but not for start?
There is no difference. The compiled JavaScript is exactly the same for two separate functions where on uses the empty parenthesis and the other doesn’t use parenthesis at all.
See sample code