ES 6付加構文


1. Shorthand property names

  • オブジェクトのキーの値と同じであれば、
  • を省略することができる.
    const a = "안녕"
    const b = "안녕"
    const same1 = { a : a, b : b }
    const same2 = { a, b } // same1과 same2 내용은 같다

    2. Destructuring assigment

  • オブジェクトの鍵を宣言した直後に
  • を使用
    const student = {
    	name : 'Anna',
        level: 1,
    }
    const {name, level } = student;
    console.log(name, level); // 출력 => 'Anna', 1
    * 다른이름으로 선언 후 사용도 가능하다.
    const { name: studentName, level: studentLevel } = student; 
    * 배열도 가능하다.
    const [first, second] = animals;
           0번째 ,  첫번째

    3. Spread Syntax

  • 配列、コピーオブジェクトのアドレス参照
    💎 アドレス値が参照されるため、コピーされた値を変更すると、既存の値も変更されます.
  • const obj1 = { key: 'key1' };
    const obj2 = { key: 'key2' };
    const array = [ obj1, obj2 ];
    //복사 후 값을 하나 추가한 형태
    const arrayCopy = [...array, {key: 'key3' }];
    console.log(arrayCopy)
    // 출력 
    { key: 'key1' }
    { key: 'key2' }
    { key: 'key3' }

    4. Default parameters

  • 関数のパラメータ値がない場合、デバッガ値
  • を設定する.
    function printMessage(message = 'default message') {
    	console.log(message);
    }
    printMessage('hello'); // 출력 => hello
    printMessage(); // 출력 => default message

    5. Ternary Operator

  • 単純条件文
  • を使用
    const component = isCat ? 'a' : 'b' ;
    isCate이 true 일때 'a'
    isCate이 false 일때 'b'가 리턴된다.

    6. Tmplate Literals

  • 文字と変数
  • を使用
    // 기존방식
    const temparature = "16도"
    console.log("지금 온도는 " + temparature + " 입니다."
    // ES6 
    console.log(`지금 온도는 ${temparature} 입니다.`);
    関連項目:https://www.youtube.com/watch?v=36HrZHzPeuY