일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Event
- css:position
- dotenv
- yet
- CSS
- ES5
- react
- Temporal dead zone
- js
- javascript
- Review
- nodeValue
- Empty
- TypingEffect
- Dom
- a11y
- for loop
- node
- es6
- keyup
- beforeinput
- UI
- innerText
- textContent
- addEventListener
- node.js
- innerHTML
- modal
- HTML
- keyboardEvent
- Today
- Total
the murmurous sea
JS: Promise.prototype.then() - incompleted 본문
1. method
2. returns a Promise.
3. As the then and Promise.prototype.catch() methods return promises, they can be chained — an operation called composition.
4. returns a Promise which allows for method chaining.
[Syntax]
p.then(onFulfilled[, onRejected]);
p.then(value => {
// fulfillment
}, reason => {
// rejection
});
onFulfilled | Optional | A Function called if the Promise is fulfilled. : has one argument, the fulfillment value. |
If it is not a function : it is internally replaced with an "Identity" function (it returns the received argument). |
||
onRejected | Optional | A Function called if the Promise is rejected. : has one argument, the rejection reason. |
If it is not a function : it is internally replaced with a "Thrower" function (it throws an error it received as argument). |
If one or both arguments are omitted or are provided non-functions
: then .then() will be missing the handler(s), but will not generate any errors.
If the Promise that .then() is called on adopts a state (fulfillment or rejection) for which .then() has no handler
: a new Promise is created with no additional handlers, simply adopting the final state of the original Promise on which .then() was called.
[Return Value]
Once a Promise is fulfilled or rejected,
the respective handler function will be called asynchronously (scheduled in the current thread loop).
The behavior of the handler function follows a specific set of rules.
If a handler function:
returns a value, | the promise returned by then() gets resolved with the returned value as its value. |
doesn't return anything, | the promise returned by then() gets resolved with an undefined value. |
throws an error, | the promise returned by then() gets rejected with the thrown error as its value. |
returns an already fulfilled promise, | the promise returned by then() gets fulfilled with that promise's value as its value. |
returns an already rejected promise, | the promise returned by then() gets rejected with that promise's value as its value. |
returns another pending promise object, | the resolution/rejection of the promise returned by then() will be subsequent to the resolution/rejection of the promise returned by the handler. Also, the resolved value of the promise returned by then() will be the same as the resolved value of the promise returned by the handler. |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
'#dev > 개념정리' 카테고리의 다른 글
pjax (0) | 2020.05.21 |
---|---|
SPA(Single Page Application) (0) | 2020.05.21 |
JS ES6: Promise (0) | 2020.05.21 |
JS ES6: symbol (0) | 2020.05.15 |
생성자 함수 (empty) (0) | 2020.05.14 |