deferred.resolve()
JQ Home <<
Objects <<
deferred.resolve()
doneCallbacks resolution.
Description
The deferred.resolve() Deferred method, resolve a Deferred object and calls any doneCallbacks with the specified arguments.
- Only the creator of a
Deferredobject should call this method. Other code can be stopped from changing Deferred object state or from reporting Deferred object status by returning a restricted Promise object through thedeferred.promise()method. - When the
deferred.resolvemethod is called, any doneCallbacks added by thedeferred.then()ordeferred.done()methods are called. - Callbacks are executed in the order they were added and each callback is passed the
argsfrom thedeferred.resolvemethod if any were specified. - Any doneCallbacks added after the
Deferredobject enters the resolved state are executed immediately when they are added, using the arguments that were passed to thedeferred.resolvemethod.
Syntax
| Signature | Description |
|---|---|
deferred.resolve( [args] ) | Resolve a Deferred object and call any doneCallbacks with the specified arguments. |
Parameters
| Parameter | Description | Type |
|---|---|---|
args | Arguments that are passed to the doneCallbacks. | Array |
Return
A Deferred object.
deferred.resolve( [args] ) ExamplesObjects << Top
Resolve a Deferred object and call any doneCallbacks with the specified arguments.
In the example below when we press the left button the first time we create a Deferred object and use some deferred object methods on it. We then resolve
the Deferred object with no arguments and process any doneCallbacks before resolving it.
When we press the right button the first time we create a Deferred object and use some deferred object methods on it. We then resolve
the Deferred object with some arguments and process any doneCallbacks before resolving it.
$(function(){
$('#btn11').one('click', function(){
var ourDeferred = $.Deferred();
ourDeferred.done( fFunc );
ourDeferred.resolve();
});
$('#btn12').one('click', function(){
var ourDeferred = $.Deferred();
ourDeferred.done( eFunc );
ourDeferred.resolve( 'Our deferred was resolved. <br><br>', '#div1' );
});
function eFunc( value, div ){
$(div).append( 'In eFunc: ' + value);
}
function fFunc(){
$('#div1').append( 'In fFunc: with no args. <br>');
}
});
div1. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 7 - The Deferred Object
