This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Reflect.getOwnPropertyDescriptor()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2016๋…„ 9์›”โฉ.

Reflect.getOwnPropertyDescriptor() ์ •์  ๋ฉ”์„œ๋“œ๋Š” ๊ฐ์ฒด์— ์ฃผ์–ด์ง„ ์†์„ฑ์ด ์กด์žฌํ•˜๋ฉด, ํ•ด๋‹น ์†์„ฑ์˜ ์„œ์ˆ ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. Object.getOwnPropertyDescriptor()์™€ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

const object1 = {
  property1: 42,
};

console.log(Reflect.getOwnPropertyDescriptor(object1, "property1").value);
// Expected output: 42

console.log(Reflect.getOwnPropertyDescriptor(object1, "property2"));
// Expected output: undefined

console.log(Reflect.getOwnPropertyDescriptor(object1, "property1").writable);
// Expected output: true

๊ตฌ๋ฌธ

js
Reflect.getOwnPropertyDescriptor(target, propertyKey);

๋งค๊ฐœ๋ณ€์ˆ˜

target

์†์„ฑ์„ ํƒ์ƒ‰ํ•  ๊ฐ์ฒด.

propertyKey

์ž์ฒด ์†์„ฑ ์„œ์ˆ ์ž๋ฅผ ๊ฐ€์ ธ์˜ฌ ์†์„ฑ์˜ ์ด๋ฆ„.

๋ฐ˜ํ™˜ ๊ฐ’

๋Œ€์ƒ ์†์„ฑ์ด ๊ฐ์ฒด์— ์กด์žฌํ•˜๋ฉด, ๊ทธ ์†์„ฑ์˜ ์„œ์ˆ ์ž. ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด undefined.

์˜ˆ์ œ

target์ด Object๊ฐ€ ์•„๋‹ˆ๋ฉด TypeError.

์„ค๋ช…

Reflect.getOwnPropertyDescriptor ๋ฉ”์„œ๋“œ๋Š” ๊ฐ์ฒด ์†์„ฑ์˜ ์„œ์ˆ ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์†์„ฑ์ด๋ผ๋ฉด undefined๋ฅผ ๋Œ€์‹  ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. Object.getOwnPropertyDescriptor()์™€์˜ ์œ ์ผํ•œ ์ฐจ์ด๋Š” ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ๋Œ€์ƒ์˜ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

์˜ˆ์ œ

Reflect.getOwnPropertyDescriptor() ์‚ฌ์šฉํ•˜๊ธฐ

js
Reflect.getOwnPropertyDescriptor({ x: "hello" }, "x");
// {value: "hello", writable: true, enumerable: true, configurable: true}

Reflect.getOwnPropertyDescriptor({ x: "hello" }, "y");
// undefined

Reflect.getOwnPropertyDescriptor([], "length");
// {value: 0, writable: true, enumerable: false, configurable: false}

Object.getOwnPropertyDescriptor()์™€์˜ ์ฐจ์ด์ 

Reflect.getOwnPropertyDescriptor()์˜ ์ฒซ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๊ฐ์ฒด๊ฐ€ ์•„๋‹ˆ๊ณ  ์›์‹œ๊ฐ’์ด๋ผ๋ฉด TypeError๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด Object.getOwnPropertyDescriptor()๋Š” ๊ฐ™์€ ์ƒํ™ฉ์—์„œ ๊ฐ’์„ ์šฐ์„  ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

js
Reflect.getOwnPropertyDescriptor("foo", 0);
// TypeError: "foo" is not non-null object

Object.getOwnPropertyDescriptor("foo", 0);
// { value: "f", writable: false, enumerable: true, configurable: false }

๋ช…์„ธ

Specification
ECMAScriptยฎ 2026 Language Specification
# sec-reflect.getownpropertydescriptor

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ