Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

CHAPTER 35: Using Deferred Objects > Using Multiple Callbacks - Pg. 986

CHAPTER 35 USING DEFERRED OBJECTS that I don't have to duplicate the code for tidying up after the task has finished in my functions that handle resolved or rejected deferred objects. Tip Callbacks functions are called in the order in which they are registered with the deferred object. In this example, I call the always method before calling the done or fail method, which means that the outcome- indifferent function is always called before the functions that handle the resolved or rejected outcomes. Using Multiple Callbacks One of the benefits that arise from using deferred objects is that you can partition your code into small functions that handle specific activities. To allow further decomposition of your code, deferred objects provide support for registering multiple callbacks for the same outcome. Listing 35-9 provides a demonstration. Listing 35-9. Registering Multiple Callback Functions with a Deferred Object ... <script type="text/javascript"> $(document).ready(function() { function performLongTaskSync() {