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.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

์„ค์ •ํ•  ๊ฐ’.

receiver Optional

์†์„ฑ์ด ์„ค์ •์ž์ผ ๊ฒฝ์šฐ, this๋กœ ์‚ฌ์šฉํ•  ๊ฐ’.

๋ฐ˜ํ™˜ ๊ฐ’

๊ฐ’ ์„ค์ •์˜ ์„ฑ๊ณต ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” Boolean.

์˜ˆ์™ธ

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

์„ค๋ช…

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ยฎ 2026 Language Specification
# sec-reflect.set

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

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