ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ES6(ES2015)
    노드!노드! 너를 어떻하면 좋겠니! 2022. 9. 12. 23:46

    var 로 선언된 변수의 통용 영역은 함수로 if, for문과 같은 블록스코프접근 가능

    const, let은 블록스코프로 if문 과 같은 블록에는 접근 불가

    const -> 상수선언 ( 변경불가 ) / 그래서 초기값선언시 반드시 값대입해야한다.

    템플릿 문자열

    백티(`)으로 감싼 문자열에 ${변수}로 쓰면 문자결합연산자쓰지 않아 가독성이 좋음

    ///////////////////////////////////////////////////////////

    object 문법의 변화

    var sayNode = function(){

       console.log('Node')

    }

    var es = 'ES'

    const newObj = {

        sayJS(){

             console.log('JS')

         },

        sayNode,

      [es + 6] : 'object 추가하기'

    }

    newObj.sayJS(); // 콘솔창에 JS가 노출됨

    newObj.sayNode(); //콘솔창에 Node가 출력됨

    console.log(newObj.ES6); // object추가하기가 콘솔창에 출력됨

    속성명과 변수명이 동일한 경우에는 한번 만 써도 됨, 변수결합표현식의 변수를 객체에 추가하려면 객체 바깥에서 정렬로 추가할 수 밖에 없었던 것을 그대로 객체안에서 선언할 수있음

    화살표함수

    function normalFun(x, y){

      retrun x+y;

    }

    const arrowFun = (x, y) => x+y;

    //return 문밖에 없는 경우에는 생략가능 // 매개인자가 하나인경우 소괄호생략가능

    기존의 함수와 다른 화살표함수의 this 바인드 (this의 대상이 같다)

    var  arrowObject = {

         name : '객체내 this',

         list : ['접근1','접근2'],

        approachFun (){

           this.list.forEach( ea => {

             console.log(this.name, ea )

           } )

        },

    }

    arrowObject.approachFun(); // 객체내 this 접근1, 객체내 this 접근2

    구조분해할당

    const candyMachine = {

    status : { name : 'node', count : 5 },

    getCandy(){

    this.status.count--;

    return this.status.count;

    },

    }

    const { getCandy , status : { count } } = candyMachine;

    배열에 대한 구조분해 할당문법

    var [ count, obj, str, , bool ] = [ 5, {}, '글자', null, true ];

     

     

     

Designed by Tistory.