Mastering JavaScript Promises

Discover and explore the world of promises, one of JavaScript's most powerful concepts

Mastering JavaScript Promises

This ebook is included in a Mapt subscription
Muzzamil Hussain

1 customer reviews
Discover and explore the world of promises, one of JavaScript's most powerful concepts
$0.00
$39.99
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781783985500
Paperback188 pages

Book Description

JavaScript is a tool for the gurus who create highly useful applications, but it has some limitations. To overcome these limitations, a concept called JavaScript promises is rising rapidly in popularity. Promises makes writing complex logics more manageable and easy.

This book starts with an introduction to JavaScript promises and how it has evolved over time. You will learn the JavaScript asynchronous model and how JavaScript handles asynchronous programming. Next, you will explore the promises paradigm and its advantages.

Finally, this book will show you how to implement promises in platforms used in project development including WinRT, jQuery, and Node.js.

Table of Contents

Chapter 1: Promises.js
The fall and rise of JavaScript
Google's contributions to JavaScript
Where Promises.js came in?
What is a promise?
Why do we need promise in JS?
Software prerequisites
Future, promise, and delay
States of a promise
How do we keep Promises.js in this book?
Browser compatibility
Summary
Chapter 2: The JavaScript Asynchronous Model
Programming models
Learning the JavaScript asynchronous model
The mechanism of a callback function in JavaScript
The events
The publisher/subscriber
The promises object
Summing up – the asynchronous programing model
Summary
Chapter 3: The Promise Paradigm
Callback, revisited
Promise
Deferred
How do promise and deferred relate to each other?
Standard behaviors of the Promise API
Interactive promises
The states and return values of a promise
Common sequencing patterns
Decoupling events and applications logic
What promises prescribed not to do
Promises and exceptions
Best practices to handle exceptions in promise
Considerations while choosing a promise
Summary
Chapter 4: Implementing Promises
How to implement promises
Implementations in Java
Say hello to JDeferred
Mechanics of JDeferred
Ultimate JDeferred
Summary
Chapter 5: Promises in WinRT
An introduction to WinRT
The evolution of WinRT
A little detail about WinJS
WinJS – its purpose and a distribution history
HTML5, CSS3, and JavaScript
WT with HTML5, CSS3, and JavaScript
The need for integrating promise with WT
Problems when using asynchronous programming
Jumpstarting promises
Writing a function that returns a promise
Error handling
Chaining promises using the then() and done() functions
Summary
Chapter 6: Promises in Node.js
The V8 engine – the mechanics
The V8 engine in Google Chrome
The evolution of Node.js
A brief introduction to Node.js
Download and install Node.js
Node Package Manager – NPM
Choice of environment
Setting up the environment for Node.js
A simple node server
Things we learned so far
Node.js with the Q library
Moving ahead with Q
Propagation in Q
Chaining and nesting promises
Sequences in Q
Combination in Q
How to handle errors in Q in Node.js
Making progress with promises
Getting to the end of a chain of promises
Callback-based promises versus Q-based promises
Q.Promise() – another way to create promises
Static methods of Q
Promise as a proxy
Familiarizing Node.js – the Q way
Unbinds and its solution
Q support for tracing stacks
Making promise-based actions
Object handling promises
View revisited
Aborting a promise
Q utilities for Node.js
Summary
Chapter 7: Promises in Angular.js
The evolution of Angular.js
The structure of the Angular.js document
Getting started with Angular.js
Creating your first Angular.js file
How to use Angular.js on your local machine
What would be your preference for the server?
Key elements of Angular.js
Implementing promises in Angular.js
The schematics of using promises in Angular.js
Promise as a handle for callback
Blindly passing arguments and nested promises
Deferred objects or composed promises
Dealing with the nested calls
Concurrency in Angular.js
The combination of success and error
The safe approach
Route your promise
Summary
Chapter 8: Promises in jQuery
From where it started?
Behind the scenes – how does jQuery work?
Is your document ready to submit?
How to use jQuery
The syntax
Caching in jQuery
A sample example
JavaScript before and after jQuery
The solution – introducing promises in jQuery
Deferred in jQuery
$.Deferred().promise() in jQuery
Projecting a promise in jQuery
Joining promises with $.when
Your own $.Deferred process
The advent of promises in jQuery
Summary
Chapter 9: JavaScript – The Future Is Now
ECMAScript 6 (ECMA 262)
harmony:generators
The MEAN stack
Real-time communication in JavaScript
Internet of Things
Computer animation and in 3D graphics
NoSQL databases
Summary

What You Will Learn

  • Get a complete overview of the promises paradigm and its advantages
  • Discover the programming models that are used to build JavaScript
  • Execute the asynchronous programming model in JavaScript and understand its usefulness in modern web development
  • Employ promises in JavaScript to boost your project performance
  • Apply the best practices of promises in JavaScript to your platform of choice
  • Manage your JavaScript code in a more professional and maintainable manner
  • Utilize promises effectively and efficiently in different domains and disciplines of software engineering
  • Implement promises in WinRT, Node.js, jQuery, and Angular.js

Authors

Table of Contents

Chapter 1: Promises.js
The fall and rise of JavaScript
Google's contributions to JavaScript
Where Promises.js came in?
What is a promise?
Why do we need promise in JS?
Software prerequisites
Future, promise, and delay
States of a promise
How do we keep Promises.js in this book?
Browser compatibility
Summary
Chapter 2: The JavaScript Asynchronous Model
Programming models
Learning the JavaScript asynchronous model
The mechanism of a callback function in JavaScript
The events
The publisher/subscriber
The promises object
Summing up – the asynchronous programing model
Summary
Chapter 3: The Promise Paradigm
Callback, revisited
Promise
Deferred
How do promise and deferred relate to each other?
Standard behaviors of the Promise API
Interactive promises
The states and return values of a promise
Common sequencing patterns
Decoupling events and applications logic
What promises prescribed not to do
Promises and exceptions
Best practices to handle exceptions in promise
Considerations while choosing a promise
Summary
Chapter 4: Implementing Promises
How to implement promises
Implementations in Java
Say hello to JDeferred
Mechanics of JDeferred
Ultimate JDeferred
Summary
Chapter 5: Promises in WinRT
An introduction to WinRT
The evolution of WinRT
A little detail about WinJS
WinJS – its purpose and a distribution history
HTML5, CSS3, and JavaScript
WT with HTML5, CSS3, and JavaScript
The need for integrating promise with WT
Problems when using asynchronous programming
Jumpstarting promises
Writing a function that returns a promise
Error handling
Chaining promises using the then() and done() functions
Summary
Chapter 6: Promises in Node.js
The V8 engine – the mechanics
The V8 engine in Google Chrome
The evolution of Node.js
A brief introduction to Node.js
Download and install Node.js
Node Package Manager – NPM
Choice of environment
Setting up the environment for Node.js
A simple node server
Things we learned so far
Node.js with the Q library
Moving ahead with Q
Propagation in Q
Chaining and nesting promises
Sequences in Q
Combination in Q
How to handle errors in Q in Node.js
Making progress with promises
Getting to the end of a chain of promises
Callback-based promises versus Q-based promises
Q.Promise() – another way to create promises
Static methods of Q
Promise as a proxy
Familiarizing Node.js – the Q way
Unbinds and its solution
Q support for tracing stacks
Making promise-based actions
Object handling promises
View revisited
Aborting a promise
Q utilities for Node.js
Summary
Chapter 7: Promises in Angular.js
The evolution of Angular.js
The structure of the Angular.js document
Getting started with Angular.js
Creating your first Angular.js file
How to use Angular.js on your local machine
What would be your preference for the server?
Key elements of Angular.js
Implementing promises in Angular.js
The schematics of using promises in Angular.js
Promise as a handle for callback
Blindly passing arguments and nested promises
Deferred objects or composed promises
Dealing with the nested calls
Concurrency in Angular.js
The combination of success and error
The safe approach
Route your promise
Summary
Chapter 8: Promises in jQuery
From where it started?
Behind the scenes – how does jQuery work?
Is your document ready to submit?
How to use jQuery
The syntax
Caching in jQuery
A sample example
JavaScript before and after jQuery
The solution – introducing promises in jQuery
Deferred in jQuery
$.Deferred().promise() in jQuery
Projecting a promise in jQuery
Joining promises with $.when
Your own $.Deferred process
The advent of promises in jQuery
Summary
Chapter 9: JavaScript – The Future Is Now
ECMAScript 6 (ECMA 262)
harmony:generators
The MEAN stack
Real-time communication in JavaScript
Internet of Things
Computer animation and in 3D graphics
NoSQL databases
Summary

Book Details

ISBN 139781783985500
Paperback188 pages
Read More
From 1 reviews

Read More Reviews