JavaScript Promises: Navigating the Terminology Maze
Promises in JavaScript have given rise to a tapestry of terms that can become overwhelming. To unravel this terminology, let's dive into the heart of Promises/A specification and ES6.
The Three States:
Promises exist in one of three states:
Settled, Fulfilled, and Resolved
The term settled encompasses both fulfilled and rejected states, indicating that the promise is no longer in a pending state. Fulfilled specifically denotes the successful acquisition of a result, while rejected signifies the failure to acquire a result.
Resolve
Resolve is a contentious term that can be interpreted in two ways:
Promises Resolved with Promises
Resolving a promise with a promise (or thenable) means adopting the state of that promise. This leads to the possibility of resolving a promise's fate without knowing whether it will be fulfilled or rejected.
Defer
Defer refers to returning an asynchronous promise for a result instead of the result itself (synchronously). This ensures that rejections are handled through deferred rejection rather than synchronous exceptions.
The above is the detailed content of Promises in JavaScript: What Does 'Resolve' Really Mean?. For more information, please follow other related articles on the PHP Chinese website!