small medium large xlarge

Back to: All Forums  CoffeeScript
07 Nov 2011, 07:46
Chris Kimpton (3 posts)


Thanks for a great book - has the right balance of light chat/detailed explanation - so that its quick to read but has depth for when you need it.

One question I have that was probably covered but I think I missed…

As brackets are optional in CoffeeScript, meaning that mentioning the function with/without the brackets results in it being called. I presume you cannot pass functions around as first class citizens, I guess you have to wrap them in an “anonymous” function, something like “-> func()”, is that right?

Thanks, Chris

13 Nov 2011, 14:11
Trevor Burnham (54 posts)

Sorry for not getting back to you sooner. You absolutely can pass functions around the same way you can in JavaScript! Unlike Ruby, CoffeeScript doesn’t make func equivalent to func(); implicit parentheses are only possible when there’s at least one argument. So the CoffeeScript code

$('li').click clickHandler

simply compiles to the JavaScript code

You must be logged in to comment