-
프로미스JavaScript 2022. 10. 5. 09:52
그간 접한 코드와 예제, 강의로는 실제로 프로미스가 활용되는 방식을 이해하는 데에 턱없이 부족하다.
더 나아간 공부가 필요하다.
resolve를 타고 then 이 어떻게 움직이는지에 대한 쉬운 예제
const countPromise = Promise.resolve(0); function increment(value) { return value + 1; } const resultPromise = countPromise.then(increment).then(increment).then(increment); resultPromise.then(console.log); // Print: 3
const firstPromise = new Promise((resolve, reject) => { resolve('First'); }); firstPromise.then((value) => { console.log(value); }); // Print: 'First'
const firstPromise = Promise.resolve('First'); firstPromise.then(console.log); // Print: 'First'
'JavaScript' 카테고리의 다른 글
이벤트 루프 (0) 2023.01.12 심볼 (0) 2022.09.30 객체 메소드 (0) 2022.09.30 계산된 프로퍼티 computed property (0) 2022.09.30 생성자 함수 (0) 2022.09.30