promise 객체가 무엇인지 fetch를 사용해서 확인해봤다.
var result = fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(function(response){
console.log('response : ', Response)
}).catch(function(error){
console.log('error : ', Error)
});
then, catch 메소드를 가지고 있으며,
then은 정상수행될때, catch는 오류가 있을때 실행된다.
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(function(response){
console.log('response : ', Response)
}).catch(function(error){
console.log('error : ', Error)
})
console.log('네트워크 통신이 끝날 떄 까지 기다리지 않고 바로 실행되요');
생각
ajax, axios, fetch를 비교하다가 promise라는 단어가 나와서 그냥 넘어갈까 하다가, 아무래도 promise가 뭔지 궁금해서... 이참에 fetch도 사용해 보았다.
별거 아닐 수 있지만, 그냥 넘어갔으면 계속 찜찜할뻔..