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
구문
Reflect.getOwnPropertyDescriptor(target, propertyKey);
매ê°ë³ì
target-
ìì±ì íìí ê°ì²´.
propertyKey-
ìì²´ ìì± ìì ì를 ê°ì ¸ì¬ ìì±ì ì´ë¦.
ë°í ê°
ëì ìì±ì´ ê°ì²´ì ì¡´ì¬íë©´, ê·¸ ìì±ì ìì ì. ì¡´ì¬íì§ ìì¼ë©´ undefined.
ìì
ì¤ëª
Reflect.getOwnPropertyDescriptor ë©ìëë ê°ì²´ ìì±ì ìì ì를 ë°íí©ëë¤. ë§ì½ ì¡´ì¬íì§ ìë ìì±ì´ë¼ë©´ undefined를 ëì ë°íí©ëë¤. Object.getOwnPropertyDescriptor()ìì ì ì¼í ì°¨ì´ë ê°ì²´ê° ìë ëìì ì²ë¦¬ ë°©ë²ì
ëë¤.
ìì
>Reflect.getOwnPropertyDescriptor() ì¬ì©í기
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()ë ê°ì ìí©ìì ê°ì ì°ì ê°ì²´ë¡ ë³íí©ëë¤.
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® 2027 Language Specification> # sec-reflect.getownpropertydescriptor> |