Chapter 6. Functions for the future: generators and promises
This chapter covers
- Continuing function execution with generators
- Handling asynchronous tasks with promises
- Achieving elegant asynchronous code by combining generators and promises
In the previous three chapters, we focused on functions, specifically on how to define functions and how to use them to great effect. Although we’ve introduced some ES6 features, such as arrow functions and block scopes, we’ve mostly been exploring features that have been part of JavaScript for quite some time. This chapter tackles the cutting edge of ES6 by presenting generators and promises, two completely new JavaScript features.
Note
Generators and promises are both introduced by ES6. You ...
Get Secrets of the JavaScript Ninja, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.