[Javascript] Promise #2
callback보다 promise를 선호하는 이유는 문법적 간편함과 보기에 편하기 떄문인데 그것이 가능한 이유가 Chaning 때문이다. 예제코드) const promise = Promise.resolve("one"); promise .then(val => { return "two" }) .then(val => console.log(val)); 실행결과 one two 이때 return 으로 넘긴 값이 다음 then 의 첫번째 인자로 넘어간다. 예제코드2) Promise.resolve("one") .then(val => { console.log(val); return new Promise(resolve => { setTimeout(() => resolve("two"), 3000); }); }) .then(..
Javascript/비동기 프로그래밍
2020. 4. 8. 00:03