Reflect.set()
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.set() ì ì ë©ìëë ê°ì²´ ìì±ì ê°ì ì¤ì í©ëë¤.
ìëí´ ë³´ê¸°
const object1 = {};
Reflect.set(object1, "property1", 42);
console.log(object1.property1);
// Expected output: 42
const array1 = ["duck", "duck", "duck"];
Reflect.set(array1, 2, "goose");
console.log(array1[2]);
// Expected output: "goose"
구문
js
Reflect.set(target, propertyKey, value[, receiver])
매ê°ë³ì
target-
ìì±ì ê°ì ì¤ì í ëì ê°ì²´.
propertyKey-
ê°ì ì¤ì í ìì±ì ì´ë¦.
value-
ì¤ì í ê°.
receiverOptional-
ìì±ì´ ì¤ì ìì¼ ê²½ì°,
thisë¡ ì¬ì©í ê°.
ë°í ê°
ê° ì¤ì ì ì±ê³µ ì¬ë¶ë¥¼ ëíë´ë Boolean.
ìì¸
ì¤ëª
Reflect.set() ë©ìëë ê°ì²´ ìì±ì ê°ì ì¤ì í ì ììµëë¤. ìì± ì¶ê°ë í ì ìì¼ë©°, í¨ìë¼ë ì ì ì ì¸íë©´ ëì ë°©ìì ìì± ì ê·¼ìì ê°ìµëë¤.
ìì
>Reflect.set() ì¬ì©í기
js
// Object
var obj = {};
Reflect.set(obj, "prop", "value"); // true
obj.prop; // "value"
// Array
var arr = ["duck", "duck", "duck"];
Reflect.set(arr, 2, "goose"); // true
arr[2]; // "goose"
// ë°°ì´ ì르기
Reflect.set(arr, "length", 1); // true
arr; // ["duck"];
// 매ê°ë³ì를 íëë§ ì ê³µíë©´ ìì± í¤ ì´ë¦ì 문ìì´ "undefined", ê°ì undefined
var obj = {};
Reflect.set(obj); // true
Reflect.getOwnPropertyDescriptor(obj, "undefined");
// { value: undefined, writable: true, enumerable: true, configurable: true }
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-reflect.set> |