Chain function call after function definition [duplicate]

人盡茶涼 提交于 2019-12-10 11:15:06

问题


How can I chain a function call after a function definition in CoffeeScript?

Equivalent javascript would be:

var foo = function () {
    // stuff
}.bar()

The only way I managed to do it is:

foo = `function () {
    // stuff
}.bar()`

But I hope for a better solution than embedding javascript in my (beautiful) coffeescript code


回答1:


Try like this:

foo = (-> stuff).bar()

For example:

square = ((x)-> x*x).bar()

Compiles into:

var square;
square = (function(x) {
  return x * x;
}).bar();


来源:https://stackoverflow.com/questions/15894232/chain-function-call-after-function-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!