JavaScript Object.getOwnPropertyDescriptor()

정의와 사용법

Object.getOwnPropertyDescriptor() 메서드는 객체 속성의 설명자를 반환합니다.

Object.getOwnPropertyDescriptor() 메서드는 원래 객체를 변경하지 않습니다.

관련 메서드:

Object.defineProperty() 속성을 추가하거나 수정합니다.

Object.defineProperties() 여러 속성을 추가하거나 수정합니다.

Object.getOwnPropertyNames() 객체의 모든 속성 이름을 반환합니다.

Object.getOwnPropertyDescriptor() 속성 설명자를 반환합니다.

Object.getOwnPropertyDescriptors() 객체의 모든 속성 설명자를 반환합니다.

实例

// 객체 생성
const person = {
  firstName: "Bill",
  lastName: "Gates",
  age: 50,
  eyeColor: "blue"
};
// 속성 설명자 가져오기
let descriptor = Object.getOwnPropertyDescriptor(person, "firstName");

직접 시도해보세요

문법

Object.getOwnPropertyDescriptor(object, property)

매개변수

매개변수 설명
object 필수. 목표 객체.
property 필수. 설명자를 얻으려는 속성 이름을 가져옵니다.

반환 값

형식 설명
Object 속성 설명자 객체.

브라우저 지원

Object.getOwnPropertyDescriptor() ECMAScript5 (ES5)의 특성입니다.

2013년 7월부터 모든 현대 브라우저는 ES5 (JavaScript 2009)를 완전히 지원합니다:

Chrome Edge Firefox Safari Opera
Chrome 23 IE/Edge 11 Firefox 21 Safari 6 Opera 15
2012년 9월 2012년 9월 2013년 4월 2012년 7월 2013년 7월