poemyear / pickpic

2 stars 0 forks source link

JavasScript references #10

Open poemyear opened 5 years ago

poemyear commented 5 years ago

자바스크립트의 Async/Await 가 Promises를 사라지게 만들 수 있는 6가지 이유

then 쓰다보니 너무 길어지는 것 발견

fetch(eventRoute)
            .then(response => {
                //console.log(response);
                return response.json();
            })
            .then(responseJson => {
                for (let event of responseJson) {
                    // console.debug(responseJson);
                    // console.error("---");    
                }

fetch를 하고 그 promise를 받아서 다시 response.json()을 하고 그 promise를 받아서 처리 then 하고 다시 then

        const responseJson = await(await fetch(eventRoute)).json();    
        for (let event of responseJson) {
            // console.debug(responseJson);
            // console.error("---");    
        }

익숙한 스타일의 코딩이 나옴

poemyear commented 5 years ago

var, let, const

let과 const의 차이점은 변수의 immutable여부이다.

let은 변수에 재할당이 가능하지만,

const는 변수 재선언, 재할당 모두 불가능하다.

먼저 var는 기본적으로 function scope를 가지게되고 let, const는 block scope를 가지게된다

poemyear commented 5 years ago

test

poemyear commented 5 years ago

trst

poemyear commented 5 years ago

Promise

poemyear commented 5 years ago

Image

Promise 에서 reject로 던진거 catch 말고 then 두번째 인자로도 받을 수 있다함