JS 내부 슬롯, 프로퍼티 어트리뷰트

HARIBO·2021년 10월 7일
0

내부 슬롯, 내부 메소드

  • 자바스크립트 엔진의 구현 알고리즘을 설명하기 위한 의사 프로퍼티, 의사 메소드이다
  • 이중 대괄호[[...]]로 감싸져 있다.
  • 엔진의 내부 로직이므로 직접적으로 접근할 수 없다.
  • [[Prototype]] 내부 슬롯같은 경우 __proto__를 통해 간접적으로 접근 가능

프로퍼티 어트리뷰트

  • 프로퍼티를 생성할 때 프로퍼티의 상태를 나타내는 프로퍼티 어트리뷰트를 기본값으로 정의
  • Object.getOwnpropertyDescriptor 는 프로퍼티 어트리뷰트 정보를 제공하는 프로퍼티 디스크립터 객체를 리턴
class Fruits {
    constructor(name, color){
        this.name = name;
        this.color = color;
    }
}

let apple = new Fruits("apple", "red");

//속성을 찾을 객체와 프로퍼티 이름을 받는다
console.log(Object.getOwnPropertyDescriptor(apple, "color"));  //{ value: 'red', writable: true, enumerable: true, configurable: true }

//모든 속성의 프로퍼티 디스크립터 객체를 리턴
console.log(Object.getOwnPropertyDescriptors(apple));

// {
//     name: {
//       value: 'apple',
//       writable: true,
//       enumerable: true,
//       configurable: true
//     },
//     color: {
//       value: 'red',
//       writable: true,
//       enumerable: true,
//       configurable: true
//     }
//   }

출처
이웅모, 모던 자바스크립트 Deep Dive(2021)

0개의 댓글