2

I want to use do to call a function without parameters like so:

do someMethod

from experimenting it seems like I can also write:

total = 42
do total.toString

question, can I do this:

return do next if request.someField == 'ok'

instead of:

return next() if request.someField == 'ok' 
2
  • I've tried it and it seems to work :) but i want to make sure it will work as intended Commented Feb 15, 2012 at 21:05
  • Also, I'm curious whether there's some kind of convention about this. Method chaining with or without parens seems to be a religious subject in coffeescript Commented Feb 15, 2012 at 21:07

1 Answer 1

1

The answer is yes.

I see you are asking about convention. The convention, AFAIK, is to use parentheses when there are no parameters: foo(), and to use do when it's convenient to wrap a few variables in a closure:

for item, index in items
  do (item, index) ->
    // Do some stuff
Sign up to request clarification or add additional context in comments.

1 Comment

That's a special-case where you can't replace do with (). Convention doesn't matter there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.