Web Dev/1. JS 문법 관련
Promise then은 Promise 객체를 반환한다
hYhY1234
2021. 2. 11. 17:07
728x90
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
Promise.prototype.then() - JavaScript | MDN
The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive
developer.mozilla.org
then은 다시 promise를 반환한다.
// 어떤 인자가 promise면 풀어서 전달해주는 함수
const convertPromise = (a, f) => (a instanceof Promise ? a.then(f) : f(a));
위의 코드에서 a.then(f)는 promise를 반환한다.