How to Create your own Promise

What is a Promise?

.resolve( 'result' )
.then( successcallback, failurecallback );

Once the promise is settled no further updates can be done to either the result or the state of the promise.

The Promise Constructor:

new Promise( executor )


if you pass a thenable object to Promise.resolve(), it will keep unwrapping the result by recursively calling Promise.resolve() until it reaches the final value.


then() and Promise chaining:

then( successcallback, failurecallback ) always returns a new Promise which gets resolved by the return value of either the successcallback or the failurecallback depending on the #state of the current Promise.






Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store