Book Image

Learning jQuery - Fourth Edition - Fourth Edition

Book Image

Learning jQuery - Fourth Edition - Fourth Edition

Overview of this book

To build interesting, interactive sites, developers are turning to JavaScript libraries such as jQuery to automate common tasks and simplify complicated ones. Because many web developers have more experience with HTML and CSS than with JavaScript, the library's design lends itself to a quick start for designers with little programming experience. Experienced programmers will also be aided by its conceptual consistency. LearningjQuery - Fourth Edition is revised and updated version of jQuery. You will learn the basics of jQuery for adding interactions and animations to your pages. Even if previous attempts at writing JavaScript have left you baffled, this book will guide you past the pitfalls associated with AJAX, events, effects, and advanced JavaScript language features. Starting with an introduction to jQuery, you will first be shown how to write a functioning jQuery program in just three lines of code. Learn how to add impact to your actions through a set of simple visual effects and to create, copy, reassemble, and embellish content using jQuery's DOM modification methods. The book will take you through many detailed, real-world examples, and even equip you to extend the jQuery library itself with your own plug-ins.
Table of Contents (24 chapters)
Learning jQuery Fourth Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Deferred objects


Deferred objects and their promises allow us to react to the completion of long-running tasks with a convenient syntax. They are discussed in detail in Chapter 11, Advanced Effects.

Object creation

Function

Description

$.Deferred([setupFunction])

Returns a new deferred object.

$.when(deferreds)

Returns a promise object to be resolved when the given deferred objects are resolved.

Methods of deferred objects

Method

Description

.resolve([args])

Sets the state of the object to resolved.

.resolveWith(context, [args])

Sets the state of the object to resolved while making the keyword this refer to context within callbacks.

.reject([args])

Sets the state of the object to rejected.

.rejectWith(context, [args])

Sets the state of the object to rejected while making the keyword this refer to context within callbacks.

.notify([args])

Executes any progress callbacks.

.notifyWith(context, [args])

Executes any progress callbacks while making the keyword this refer to context.

.promise([target])

Returns a promise object corresponding to this deferred object.

Methods of promise objects

Method

Description

.done(callback)

Executes callback when the object is resolved.

.fail(callback)

Executes callback when the object is rejected.

.always(callback)

Executes callback when the object is resolved or rejected.

.then(doneCallbacks, failCallbacks)

Executes doneCallbacks when the object is resolved, or failCallbacks when the object is rejected.

.progress(callback)

Executes callback each time the object receives a progress notification.

.isRejected()

Returns true if the object has been rejected.

.isResolved()

Returns true if the object has been resolved.

.state()

Returns 'pending', 'resolved', or 'rejected' depending on the current state.

.pipe([doneFilter], [failFilter])

Returns a new promise object which is resolved when the original promise is, optionally after filtering the object's status through a function.