在CoffeeScript中,如何使用匿名函数作为参数调用函数? [英] In CoffeeScript, how can you make a function call with anonymous functions as parameters?
本文介绍了在CoffeeScript中,如何使用匿名函数作为参数调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面给出了与匿名函数相关的语法错误:
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: "
以下作品:
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: "
这应该可以解决。
这篇关于在CoffeeScript中,如何使用匿名函数作为参数调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文