In CoffeeScript, how can you make a function call

2019-08-21 12:40发布

The following gives a syntax error related to the anonymous function:

my_function = (f, x, str) ->
  alert str + f(x)

my_function (x) -> 1 + x, 12, "The answer is: "

The following works:

my_function = (f, x, str) ->
  alert str + f(x)

increment = (x) -> x + 1

my_function increment, 12, "The answer is: "

1条回答
狗以群分
2楼-- · 2019-08-21 13:09
my_function ((x) -> x + 1), 12, "The answer is: "

That should fix it.

查看更多
登录 后发表回答