Coffeescript — How to create a self-initiating anonymous function?

后端 未结 8 1561
半阙折子戏
半阙折子戏 2021-01-29 23:43

How to write this in coffeescript?

f = (function(){
   // something
})();

Thanks for any tips :)

8条回答
  •  无人共我
    2021-01-29 23:51

    If you want to "alias" the arguments passed to self-invoking function in CoffeeScript, and let's say this is what you are trying to achieve:

    (function ( global, doc ) {
      // your code in local scope goes here
    })( window, document );
    

    Then do (window, document) -> won't let you do that. The way to go is with parens then:

    (( global, doc ) -> 
      # your code here
    )( window, document ) 
    

提交回复
热议问题