CoffeeScript creates a wrapper function with arguments passed

How can I generate this output using CoffeScript?

(function(doc) {})(document); 
+4
source share
3 answers
 ((doc) -> )(document) 

will generate

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

If you ask in the context of wrapping something in closure - for example, the JQuery plugin - this is not needed. See this question

+4
source

Not quite what you requested, but the spirit of the code is the same and it is more coffeescriptish:

 do (document) -> # whatever 

which compiles to

 (function(document) {})(document); 
+10
source
 do (doc=document) -> 

compiles to

 (function(doc) {})(document); 
+1
source

Source: https://habr.com/ru/post/1394205/


All Articles