JS: Promise .prototype .then
Promise .prototype .then
(new in ECMAScript 2015)
promise_object.then(onFulfilled,onRejected)-
onFulfilled and onRejected are both functions of 1 parameter.
onFulfilled and onRejected are optional.
- when the promise_object is fulfilled, onFulfilled is called with an arg xresult, where xresult is the arg passed to resolve function in the promise executor function body.
- when the promise_object is rejected, onRejected is called with an arg xerror, where xerror is the arg passed to reject function in the promise executor function body.
The then-method returns a new promise object.
The new promise gets fulfilled if onFulfilled or onRejected runs successfully. gets rejected if onFulfilled or onRejected throws.