Book Image

Learning jQuery 3 - Fifth Edition

By : Jonathan Chaffer
Book Image

Learning jQuery 3 - Fifth Edition

By: Jonathan Chaffer

Overview of this book

If you are a web developer and want to create web applications that look good, are efficient, have rich user interfaces, and integrate seamlessly with any backend using AJAX, then this book is the ideal match for you. We’ll show you how you can integrate jQuery 3.0 into your web pages, avoid complex JavaScript code, create brilliant animation effects for your web applications, and create a flawless app. We start by configuring and customising the jQuery environment, and getting hands-on with DOM manipulation. Next, we’ll explore event handling advanced animations, creating optimised user interfaces, and building useful third-party plugins. Also, we'll learn how to integrate jQuery with your favourite back-end framework. Moving on, we’ll learn how the ECMAScript 6 features affect your web development process with jQuery. we’ll discover how to use the newly introduced JavaScript promises and the new animation API in jQuery 3.0 in great detail, along with sample code and examples. By the end of the book, you will be able to successfully create a fully featured and efficient single page web application and leverage all the new features of jQuery 3.0 effectively.
Table of Contents (16 chapters)

Using deferred objects


At times, we come across situations in which we want to act when a process completes, but we don't necessarily know how long the process will take, or even if it will be successful. To handle these cases, jQuery offers us deferred objects (promises). A deferred object encapsulates an operation that takes some time to complete.

A new deferred object can be created at any time by calling the $.Deferred() constructor. Once we have such an object, we can perform long-running operations and then call the .resolve() or .reject() methods on the object to indicate whether the operation was successful or unsuccessful. It is somewhat unusual to do this manually, however. Typically, rather than creating our own deferred objects by hand, jQuery or its plugins will create the object and take care of resolving or rejecting it. We just need to learn how to use the object that is created.

Note

Rather than detailing how the $.Deferred() constructor operates, we will focus here on how...