方法链接函数参数 [英] Method chaining with function arguments
本文介绍了方法链接函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在CoffeeScript中链接方法的最佳方法是什么?例如,如果我有这个JavaScript,我怎么能写在CoffeeScript?
What's the best way to chain methods in CoffeeScript? For example, if I have this JavaScript how could I write it in CoffeeScript?
var req = $.get('foo.htm')
.success(function( response ){
// do something
// ...
})
.error(function(){
// do something
// ...
});
推荐答案
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();
});
这篇关于方法链接函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文