Dojo Dijit and HTML5 in Real world applications/Dojo/dojo.Deferred

From PMISwiki
Jump to: navigation, search

More to come..

dojo.Deferred

Dojo.Deferred is used to define custom made callback functions.

The example below define a deferred function that is called after timer time-out of 2 seconds.

<script type="text/javascript">
  function createDeferred(){
        console.log("Deferred button clicked"); 
        // Create a deferred and set it to fire in 2 second.
        var myDeferred = new dojo.Deferred();
        setTimeout(function(){ myDeferred.resolve({called: true});}, 2000);
        dojo.byId("response").innerHTML = "Created a deferred.";
 
        // Add a callback that changes the displayed message after it fires.
        myDeferred.then(function(){
          dojo.byId("response").innerHTML = "Deferred has fired.";
        });
    }
 
</script>

The code above may be tested here: Real world examples..

Verified in

IE 8, Firefox 3.6.22, Dojo 1.6.1, Dojo 1.7.2

References

Document History

Version Date Author Status Purpose of update
1 13 Apr 2012 PSA Draft Not released.