ABOUT ME

jacey.park.dev@gmail.com \n 5년차 프론트엔드 개발자

Today
-
Yesterday
-
Total
-
  • [JS] ECMA2018 : ES9 알아보기
    Dev/JS 2018. 4. 28. 21:21



    ES9


    마지막으로 진행된 TC39 회의에서 "ECMAScript 2018 Language Specification" 에 적용할 새로운 기능들이 정해졌습니다. 


    기능들은 ES8의 통합 이후, 4단계에 도달한 모든 기능들이 선택되었습니다.


    이 글에서는 간단한 3가지 기능들을 알아봅니다.


    ㄴ> 4단계 : TC39 위원회에서는 5단계에 이르는 프로세스를 통해 새로운 기능을 개발합니다. 이때 4단계는 "완료" 단계라고 할 수 있습니다.



    Rest/Spread Properties


    구조가 해체될 때, Rest/Spread Properties 는 선택되지 않은 객체의 남은 프로퍼티들을 새로운 객체에 옮겨집니다.



    Rest Properties



    const data = { a: 1, b: 2, c: 3, d: 4};
    const { a, b, ...remain} = data;

    console.log(a); // 1
    console.log(b); // 2
    console.log(remain) //{ c:3, d:4 }





    Spread Properties



    const Arr1 = { a: 1, b: 2, c: 3, d: 4};
    const newArr = { a: 2, e: 5, ...Arr1 };

    console.log(newArr); //{a: 1, e: 5, b: 2, c: 3, d: 4}




    for - await - of


    비동기 iterable 객체를 반복하는 구문입니다. Async for - of 문은 비동기 함수와, 비동기 generator 함수 내에서만 사용가능합니다.


    이를 통해 promise.all 로 한번에 처리하던 구문을 generator 와 for - of 를 같이 사용하게 해줌으로써 반복적인 비동기 처리가 가능해졌습니다.


    참고 : https://www.zerocho.com/category/EcmaScript/post/5adae68aca91b1001b14dd29



    for await (const line of readLines(filePath)) {
    console.log(line);
    }




    Promise.prototype.finally()


    Promise에 finally() 라는 메소드가 추가되었습니다. 실행결과에 상관없이 맨 마지막에 실행되는 메소드 입니다.



    fetch('http://example.com/endpoint')
    .then(result => {

    })
    .catch((err) => {

    })
    .finally(() => {

    })

     


    참고

    https://medium.com/front-end-hacking/javascript-whats-new-in-ecmascript-2018-es2018-17ede97f36d5

    https://www.zerocho.com/category/EcmaScript/post/5adae68aca91b1001b14dd29

    https://github.com/tc39/proposal-promise-finally


    댓글

Designed by Tistory.