When I want to write a class in Coffeescript that provides method chaining I often come up with the problem of having a one liner in principle but then having to add a line to actually return the instance for the chaining.
So instead of writing a simple setter like this:
class myClass
setProperty: (value) -> @property = value
I have to break it up and do it like this:
class myClass
setProperty: (value) ->
@property = value
@
In my eyes this really reduces readability and compactness of the code, especially if you have plenty of setters and other self-explanatory one liners.
So I thought about doing it another way and reintroducing the semicolon to my code, like this:
class myClass
setProperty: (value) -> @property = value; @
The compiled JavaScript is actually the same, but while it's pretty handy it also feels a little dirty to do it that way.
How would you serve the purpose of method chaining (if you'd use it) in Coffeescript?
EDIT: The best solution I got so far, a clean and short one-liner without any semicolons:
class myClass
setProperty: (@property) -> @