【发布时间】:2012-09-16 16:18:55
【问题描述】:
我有一个必须从 Coffeescript 生成的函数:
$("#user-tabs ul").idTabs({
click: function(id, all, container, settings) {
alert(id);
}
});
所以,我写了以下咖啡脚本:
$("#user-tabs ul").idTabs ->
click: (id, all, container, settings) ->
alert(id)
return
但它不起作用。在输出 (.js) 我生成了以下代码:
$("#user-tabs ul").idTabs(function() {
return {
click: function(id, all, container, settings) {
alert(id);
}
};
});
所以,click 函数是正确编写的,但它被一些“函数返回”闭包包裹。如何重写它以达到所需的代码(在最顶部)?有可能吗?
谢谢!
【问题讨论】:
-
->不是用于在 CoffeeScript 中定义函数吗?因此,您在第一行中定义了它。尝试改变它。
标签: javascript jquery coffeescript return anonymous-function