4

How can I generate this output with CoffeScript?

(function(doc) {})(document);

3 Answers 3

10

Not exactly what you have asked, but the spirit of the code is the same and it is more coffeescriptish :

do (document) ->
   # whatever

which compiles to

(function(document) {})(document);
Sign up to request clarification or add additional context in comments.

Comments

4
((doc) ->
)(document)

will generate

(function(doc) {})(document);

If you're asking in the context of wrapping something in a closure - for instance a JQuery plugin - this will not be needed. See this question

2 Comments

I'm deleting my response since it's the same. We answered at exactly the same time.
One thing I did add: "You don't generally need to do this since your CoffeeScript is enclosed in a similar anonymous function by default."
1
do (doc=document) ->

compiles to

(function(doc) {})(document);

Comments

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.