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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 01:27:15

问题


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:


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

That should fix it.



来源:https://stackoverflow.com/questions/6720402/in-coffeescript-how-can-you-make-a-function-call-with-anonymous-functions-as-pa

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