【问题标题】:Coffeescript and jQuery chainingCoffeescript 和 jQuery 链接
【发布时间】:2012-06-27 01:38:16
【问题描述】:
我正在咖啡脚本中尝试这个:
$( element ).mousedown( aFunction ).mouseup( anotherFunction );
我正在尝试找到一种利用缩进的方法,以便如下所示的内容将返回内容:
$ element
.mousedown aFunction
.mouseup anotherFunction
但无济于事,有没有关于在咖啡脚本中进行链接的建议?
【问题讨论】:
标签:
coffeescript
chaining
【解决方案1】:
我确定您不想使用括号,但是...
$("#element")
.mousedown(aFunction)
.mouseup(anotherFunction)
编译成
$("#element").mousedown(aFunction).mouseup(anotherFunction);
【解决方案2】:
对于所有其他快速读者,这是a paid nerd 给出的here 的更新答案。
req = $.get('foo.html')
.success (response) ->
do_something()
.error (response) ->
do_something()
...编译为:
var req;
req = $.get('foo.html').success(function(response) {
return do_something();
}).error(function(response) {
return do_something();
});
看起来mus is too short 也在上面的评论中提出了建议。