deferred.resolve()S2C 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 Deferred object 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 the deferred.promise() method.
  • When the deferred.resolve method is called, any doneCallbacks added by the deferred.then() or deferred.done() methods are called.
  • Callbacks are executed in the order they were added and each callback is passed the args from the deferred.resolve method if any were specified.
  • Any doneCallbacks added after the Deferred object enters the resolved state are executed immediately when they are added, using the arguments that were passed to the deferred.resolve method.

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] ) ExamplesTop

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.

Press the button below to action the above code: