개발/Javascript

프로퍼티(Properties)

DANIEL.OH 2018. 3. 11. 14:12

프로퍼티(Properties)

  • Use dot notation when accessing properties.

  • 프로퍼티에 억세스하는 경우는 점 . 을 사용해 주십시오.

    const luke = {
      jedi: true,
      age: 28,
    };
    
    // bad
    const isJedi = luke['jedi'];
    
    // good
    const isJedi = luke.jedi;
  • Use subscript notation [] when accessing properties with a variable.

  • 변수를 사용해 프로퍼티에 억세스하는 경우는 대괄호 [] 를 사용해 주십시오.

    const luke = {
      jedi: true,
      age: 28,
    };
    
    function getProp(prop) {
      return luke[prop];
    }
    
    const isJedi = getProp('jedi');