Deferred objeccts and their promises allow us to react to the conpletion of long-running tasks with a convenient syntax.
Object creation
Object creation
Function |
Description |
$.Deferred([setupFunction]) |
Returns a new deferred object. |
$.when(deferreds) |
Returns a promise object to be resolved when the given deferred objecs are resolved. |
Methods of deferred objects
Methods of deferred objects
Method |
Description |
.resolve([args]) |
Sets the state of the object to resolved. |
.resolveWith(context, [args]) |
Sets the state of the objec to resolved while making the keyword this refer to context within callbacks. |
.rejectWith([args]) |
Sets the state of the object to rejected. |
.rejectWith(context, [args]) |
Sets the state of the object to rejected while making the keyword this refer to context within callbacks. |
.notify([args]) |
Executes any progress callbacks. |
.notifyWith(context, [args]) |
Executes any progress callback while making the keyword this refer to context. |
.promise([target]) |
Returns a promise object corresponding to this deferred object. |
Methods of promise objects
Methods of promise objects
Method |
Description |
.done(callback) |
Executes callback when the object is resolved. |
.fail(callback) |
Executes callback when the object is rejected. |
.always(callback) |
Executes callback when the object is resolved or rejected. |
.then(doneCallbacks, failCallbacks) |
Executes doneCallbacks when the object is resolved, or failCallbacks when the object is rejected. |
.progress(callback) |
Executes callback each time the object receives a progress notification. |
.isRejected() |
Returns true if the object has been rejected. |
.isResolved() |
Returns true if the object has been resolved. |
.state() |
Returns ‘pending’, ‘resolved’, or ‘rejected’ depending on the current state. |
.pipe([doneFilter], [failFilter]) |
Returns a new promise object which is resolved when the original promise is, optionally after filtering the object’s status through a function. |
最新评论
大哥资深网民啊,01年我还在念小学。。
看着有点难过。。。
嘿嘿,谢谢老哥,也祝老哥事业蒸蒸日上。
我是你唯一的药学类友情链接网站。 作为一个80后的过来人祝福你,生活越来越好。
这篇文章,我们中学那会老师课堂上念给我们听的。
哈哈哈哈哈,没想到啊, 我有手抄版
嗯,是的
好心办坏事多了去啦
哈哈,是的,我15年末来上海写代码了,一晃三年多过去了,好快。
今天看QQ好友的时候突然看到了你的名字,想起几年前在药品国际注册群挺活跃/厉害的你,现在不见踪影了。就搜了一下,没想到你现在转行去写代码了... (刚才打漏了一句话...)