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

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

How to write this in coffeescript?

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

Thanks for any tips :)

8条回答
  •  死守一世寂寞
    2021-01-29 23:58

    You can also combine the do keyword with default function parameters to seed recursive "self-initiating functions" with an initial value. Example:

    do recursivelyPrint = (a=0) ->
      console.log a
      setTimeout (-> recursivelyPrint a + 1), 1000
    

提交回复
热议问题