admin管理员组文章数量:1287651
I want to pass some extra parameters to a jQuery.Deferred done callback, I'm doing it like this now:
//dfd gets defined here as the return value of jQuery.ajax
var me = this;
var selector = $("#selector");
dfd.done(function(response){
me.updated(response, selector);
});
I was wondering if there is a better way to do this? I thought I had read somewhere about a cleaner way to pass parameters without the need of an anonymous wrapper function but I can't for the life of me remember where I read it, or what I read. Google searches turned up nothing so far.
I want to pass some extra parameters to a jQuery.Deferred done callback, I'm doing it like this now:
//dfd gets defined here as the return value of jQuery.ajax
var me = this;
var selector = $("#selector");
dfd.done(function(response){
me.updated(response, selector);
});
I was wondering if there is a better way to do this? I thought I had read somewhere about a cleaner way to pass parameters without the need of an anonymous wrapper function but I can't for the life of me remember where I read it, or what I read. Google searches turned up nothing so far.
Share Improve this question asked Sep 7, 2012 at 9:00 AsciiomAsciiom 9,9757 gold badges41 silver badges59 bronze badges1 Answer
Reset to default 10In order to pass something to .done
callback you need to pass it in .resolve
, for example
dfd.done( function(selector) {
console.log( selector );
});
dfd.resolve( selector );
but in your case dfd
is a $.ajax
object and .resolve
is called internally, so you have no control over it. Therefore the only way to do that is to use anonymous function and closure.
By the way: there is nothing unclean about this solution.
本文标签: javascriptPass extra parameters to jqueryDeferred callbackStack Overflow
版权声明:本文标题:javascript - Pass extra parameters to jquery.Deferred callback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741316249a2371931.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论