开发者

In CoffeeScript, how can you make a function call with anonymous functions as parameters?

开发者 https://www.devze.com 2023-03-21 06:12 出处:网络
The following gives a syntax error related to the anonymous function: my_function = (f, x, str) -> alert str + f(x)

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

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

my_function (x) -&开发者_运维技巧gt; 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: "


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

That should fix it.

0

精彩评论

暂无评论...
验证码 换一张
取 消