In this lesson we introduced you to promises, a better pattern for dealing with asynchronous code. Promises enable you to avoid having to use nasty tricks to synchronize parallel asynchronous functions and the need to nest callbacks inside callbacks inside callbacks.
We outlined the Promises/A and the Promises/A+ proposals and explained how they compare with jQuery’s implementation of promises. We also illustrated the differences that the two proposals have, focusing our attention on the different terminology adopted and the number of parameters specified for the then() method, the core of promises.
The jQuery implementation of promises involves two objects: Deferred and Promise. As we described, the latter is created starting from a Deferred or a jQuery object and possesses a subset of the methods of the Deferred.
We delved into the many methods exposed by Deferred. The latter can be resolved using the deferred.resolve() method or rejected using deferred.reject(). You can also be notified about the progress of the asynchronous operation using deferred.notify(). All these methods have a related method that accepts an additional parameter, which allows you to set the context of the functions triggered: deferred.resolveWith(), deferred.rejectWith(), and deferred.notifyWith().
deferred.done(), deferred.fail(), and deferred.progress() are the methods that enable you to add handlers to run when a Deferred is resolved, rejected, or still in progress.
Another interesting concept is $.when(), a utility function that allows you to easily synchronize multiple asynchronous and even synchronous functions.
We introduced you to jQuery’s implementation of the then() method, high-lighting the differences that jQuery has with other libraries that adhere to either the Promises/A or the Promises/A+ proposal.
This lesson also covered other methods exposed by the Deferred object, like deferred.always() and deferred.state().
Finally, we discussed promise(), a method to transform any jQuery object into a Promise object. This method is very useful because it enables you to use the power of DefeIn this lesson we introduced you to promises, a better pattern for dealing with asynchronous code. Promises enable you to avoid having to use nasty tricks to synchronize parallel asynchronous functions and the need to nest callbacks inside callbacks inside callbacks.
We outlined the Promises/A and the Promises/A+ proposals and explained how they compare with jQuery’s implementation of promises. We also illustrated the differences that the two proposals have, focusing our attention on the different terminology adopted and the number of parameters specified for the then() method, the core of promises.
The jQuery implementation of promises involves two objects: Deferred and Promise. As we described, the latter is created starting from a Deferred or a jQuery object and possesses a subset of the methods of the Deferred.
We delved into the many methods exposed by Deferred. The latter can be resolved using the deferred.resolve() method or rejected using deferred.reject(). You can also be notified about the progress of the asynchronous operation using deferred.notify(). All these methods have a related method that accepts an additional parameter, which allows you to set the context of the functions triggered: deferred.resolveWith(), deferred.rejectWith(), and deferred.notifyWith().
deferred.done(), deferred.fail(), and deferred.progress() are the methods that enable you to add handlers to run when a Deferred is resolved, rejected, or still in progress.
Another interesting concept is $.when(), a utility function that allows you to easily synchronize multiple asynchronous and even synchronous functions.
We introduced you to jQuery’s implementation of the then() method, high-lighting the differences that jQuery has with other libraries that adhere to either the Promises/A or the Promises/A+ proposal.
This lesson also covered other methods exposed by the Deferred object, like deferred.always() and deferred.state().
Finally, we discussed promise(), a method to transform any jQuery object into a Promise object. This method is very useful because it enables you to use the power of Deferreds with simple jQuery objects.
With this lesson we’ve completed our overview of the jQuery library. Thanks to the lessons you’ve read so far, you’ve hopefully learned the ins and the outs of this library and you can now define yourself as a jQuery ninja! Congratulations!
In the next lesson we’ll try to move a step forward by discussing a crucial concept that every professional developer has to master: unit testing. Turn the page and continue your learning process.rreds with simple jQuery objects.
With this lesson we’ve completed our overview of the jQuery library. Thanks to the lessons you’ve read so far, you’ve hopefully learned the ins and the outs of this library and you can now define yourself as a jQuery ninja! Congratulations!
In the next lesson we’ll try to move a step forward by discussing a crucial concept that every professional developer has to master: unit testing. Turn the page and continue your learning process.
Leave a Reply