O'Reilly logo

Learning ECMAScript 6 by Narayan Prusty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing asynchronous code

ES5 natively supports two patterns for writing the asynchronous code, that is, the event pattern and the callback pattern. While writing the asynchronous code, we usually start an asynchronous operation and register the event handlers or pass the callbacks, which will be executed once the operation is finished.

The event handlers or the callbacks are used, depending on how the specific asynchronous API is designed. An API that is designed for an event pattern can be wrapped with some custom code to create the callback pattern for the API, and vice-versa. For example, AJAX is designed for the event pattern, but jQuery AJAX exposes it as a callback pattern.

Let's consider some examples of writing asynchronous code involving ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required