My Understanding towards Promise/A+
Personal comprehension about ES6 promise,including simulated promise implementation
For a stupid Instance
There’s a scene that you’re going to order a cup of coffee.The pretty waitress may say ‘Please come to get your coffee later’.So this is a
Definition
The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.MDN
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function.(That’s why it can avoid callback hell,once you call then() method,it will implicitly
More advantages:
Unlike old-style passed-in callbacks, a promise comes with some guarantees:
1. Callbacks will never be called before the completion of the current run of the JavaScript event loop.
2. Callbacks added with .then even after the success or failure of the asynchronous operation, will be called, as above.
3. Multiple callbacks may be added by calling .then several times, to be executed independently in insertion order.
But the most immediate benefit of promises is chaining.
For more detail:Promise A+
Following my code about a simple promise implementation:
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!