The promises object is the last of the major concepts of asynchronous programming model implemented. We will be looking at promise as a design pattern.
Promise is a relatively new concept in JavaScript, but it's been around for a long time and has been implemented in other languages.
Promise is an abstraction that contains two main properties, which make them easier to work with:
You can attach more than one callback with a single promise
Values and states (errors) get passed along
Due to these properties, a promise makes common asynchronous patterns using callback easy
A promise can be defined as:
A promise is an observable token given from one object to another. Promises wrap an operation and notify their observers when the operation either succeeds or fails.
The source of this definition is Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley Professional.
Since the scope of this book revolves around the promise and how it is implemented, we will discuss...