【发布时间】:2014-06-16 12:42:04
【问题描述】:
这种模式在 jQuery 或 javascript 中是否可行?:
$.when(function(){
//I init many plugins here, some of them use ajax etc but I dont really control it
//I only do something like $(div).somePlugin() here
$("div").myPlugin()
}).done(function(){
//and this part I want to be executed when all ajaxes and deferred stuff from when part is done
//however I cannot go to every plugin and add something like deferred.resolve() etc.
});
例如,myPlugin 会有
$.fn.myPlugin = function(){
$(this).load(someUrl);
};
(但我无法将 myPlugin 更改为它的一些外部代码。)
基本上我发生了很多事情,其中很多都使用async。功能。当所有这些async 时,我想执行一些功能。东西已经完成了,但我不能更改插件代码,所以我不能添加.resolve() 东西。
【问题讨论】:
-
这取决于 - 如果它们只是常规方法,我看不出任何意义。
-
我写的很多都是异步方法。
-
like - 你能发一个例子吗?
-
添加了一些插件的例子
-
投反对票的人,请记住,这是一个完全合理的问题,也是人们面临的一个非常普遍的问题。
标签: javascript jquery asynchronous promise jquery-deferred