Home πŸ“Έ 2022-11-07
Post
Cancel

πŸ“Έ 2022-11-07

πŸ”₯ 였늘 어디에 도전해보셨고, 무엇을 λ°°μš°μ…¨λ‚˜μš”?

🌊 ν•™μŠ΅ν•˜μ‹œλ©΄μ„œ κΆκΈˆν•˜μ‹  λΆ€λΆ„μ΄λ‚˜, μ–΄λ €μ› λ˜ 점은 λ­˜κΉŒμš”?

  • κ³„μ‚°λœ ν”„λ‘œνΌν‹°(computed property)λΌλŠ” ES6 κΈ°λŠ₯을 μ‚¬μš©ν•˜λ©΄ λŒ€κ΄„ν˜Έλ₯Ό 객체 λ¦¬ν„°λŸ΄ μ•ˆμ— 넣을 수 μžˆλ‹€.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    const PROPERTY_NAME = "p1";
    function computerPropertyName() {
      return "p2";
    }
    
    // 1️⃣ λ³€μˆ˜μ— μ €μž₯λ˜μ–΄ μžˆκ±°λ‚˜ ν•¨μˆ˜μ˜ λ°˜ν™˜ 값일 λ•Œμ—λŠ” 객체λ₯Ό λ¨Όμ € λ§Œλ“€κ³  λŒ€κ΄„ν˜Έλ‘œ ν”„λ‘œνΌν‹°λ₯Ό μΆ”κ°€ν•˜λŠ” 과정이 ν•„μš”ν•˜λ‹€.
    let o = {};
    o[PROPERTY_NAME] = 1;
    o[computerPropertyName()] = 2;
    
    // 2️⃣ ES6의 κ³„μ‚°λœ ν”„λ‘œνΌν‹° κΈ°λŠ₯을 μ‚¬μš©ν•˜λ©΄ 객체 μ„ μ–Έκ³Ό λ™μ‹œμ— λŒ€κ΄„ν˜Έλ‘œ ν”„λ‘œνΌν‹°λ₯Ό μ΄ˆκΈ°ν™”ν•  수 μžˆλ‹€.
    let o = {
      [PROPERTY_NAME] : 1;
      [computerPropertyName()] : 2;
    
      // μ¦‰μ‹œμ‹€ν–‰ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ λ°”λ‘œ ν‰κ°€ν•˜κΈ°
      [(() => "p3")()] : 3;
    };
    
    console.log(o); // {p1: 1, p2: 2, p3: 3}
    

🌟 내일은 μ–΄λ–»κ²Œ 해보고 μ‹ΆμœΌμ„Έμš”?

This post is licensed under CC BY 4.0 by the author.

πŸ„πŸ»β€β™€οΈ [μžλ°”μŠ€ν¬λ¦½νŠΈ] 두 큐 ν•© κ°™κ²Œ λ§Œλ“€κΈ°

πŸ“Έ 2022-11-10