return a function without params in coffeescript using do
-
25-10-2019 - |
سؤال
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'
المحلول
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
لا تنتمي إلى StackOverflow