我试图了解两者之间的区别
I am trying to understand the difference between
$.when(...).then(...) $.when(...).done(...)在jQuery中.据我了解,当内部对象完成加载时,它们都将执行.但是有什么区别.实例将不胜感激.
in jQuery. As far as I understood both of them executes when objects inside when are finished loading. But what is the difference. Examples will be really appreciated.
推荐答案.done()仅具有成功回调.
.then()同时具有成功和失败回调.
.then() has both success and fail callbacks.
从jQuery 1.8开始,deferred.then()方法返回一个新的Promise 可以过滤通过 函数,替换现在不推荐使用的deferred.pipe()方法.
As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method.
deferred.done()方法接受一个或多个参数,所有这些参数 可以是单个函数或函数数组.
The deferred.done() method accepts one or more arguments, all of which can be either a single function or an array of functions.
由于deferred.done()返回延迟的对象,因此其他方法 可以将延迟的对象链接到此对象,包括其他对象 .done()方法.解决延迟问题后,将完成doneCallbacks 使用提供给resolve或resolveWith的参数执行 方法按照添加顺序进行调用.
Since deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one, including additional .done() methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the resolve or resolveWith method call in the order they were added.
更多推荐
jQuery $ .when().then()和.done()之间的区别
发布评论