비동기 (1) 썸네일형 리스트형 [자바스크립트] Promise Promise Promise는 비동기로 실행되는 작업의 결과를 나타내는 객체이다. new 생성자로 Promise를 생성할 수 있다. 기본 예제 function getData() { return new Promise(function(resolve, reject) { resolve(); reject(); }); } getData() .then() .catch(); Promise의 상태 Pending(대기): new Promise()로 생성하면 대기 상태가 된다. Fulfilled(이행): resolve() 를 실행하면 이행 상태가 된다. Rejected(실패): reject() 를 실행하면 실패 상태가 된다. 여러 개의 Promise를 사용하기 getDate() .then(func1) .then(func2).. 이전 1 다음