Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A cleaner way of doing the immediately-invoking function in CS is to use a `do` statement.

    MyModule = do ->
      # module body
No need for any parens.


And you don't even need to use assignment. This works as well:

    do ->
      # module body


you don't need to assign it to something, unless you need to assign it to something.

sounds like op was specifically referencing to parens for execution.


Interesting, I looked this up.

> CoffeeScript provides the do keyword, which immediately invokes a passed function, forwarding any arguments.

Apparently in April 2012 they updated the code to make it simulate namespacing.

> A tweak to the semantics of do, which can now be used to more easily simulate a namespace: do (x = 1, y = 2) -> ...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: