1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
---
title: Reflect.set()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/set
tags:
- ECMAScript 2015
- JavaScript
- Method
- Reference
- Reflect
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/set
---
<div>{{JSRef}}</div>
<p><code><strong>Reflect</strong></code><strong><code>.set()</code></strong> 정적 메서드는 객체 속성의 값을 설정합니다.</p>
<div>{{EmbedInteractiveExample("pages/js/reflect-set.html")}}</div>
<h2 id="구문">구문</h2>
<pre class="syntaxbox">Reflect.set(<em>target</em>, <em>propertyKey</em>, <em>value</em>[, <em>receiver</em>])
</pre>
<h3 id="매개변수">매개변수</h3>
<dl>
<dt><code>target</code></dt>
<dd>속성의 값을 설정할 대상 객체.</dd>
<dt><code>propertyKey</code></dt>
<dd>값을 설정할 속성의 이름.</dd>
<dt><code>value</code></dt>
<dd>설정할 값.</dd>
<dt><code>receiver</code> {{optional_inline}}</dt>
<dd>속성이 설정자일 경우, <code>this</code>로 사용할 값.</dd>
</dl>
<h3 id="반환_값">반환 값</h3>
<p>값 설정의 성공 여부를 나타내는 {{jsxref("Boolean")}}.</p>
<h3 id="예외">예외</h3>
<p><code>target</code>이 {{jsxref("Object")}}가 아니면 {{jsxref("TypeError")}}.</p>
<h2 id="설명">설명</h2>
<p><code>Reflect.set()</code> 메서드는 객체 속성의 값을 설정할 수 있습니다. 속성 추가도 할 수 있으며, 함수라는 점을 제외하면 동작 방식은 <a href="/ko/docs/Web/JavaScript/Reference/Operators/Property_Accessors">속성 접근자</a>와 같습니다.</p>
<h2 id="예제">예제</h2>
<h3 id="Reflect.set()_사용하기"><code>Reflect.set()</code> 사용하기</h3>
<pre class="brush: 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 }
</pre>
<h2 id="명세">명세</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('ES2015', '#sec-reflect.set', 'Reflect.set')}}</td>
<td>{{Spec2('ES2015')}}</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-reflect.set', 'Reflect.set')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="브라우저_호환성">브라우저 호환성</h2>
<p>{{Compat("javascript.builtins.Reflect.set")}}</p>
<h2 id="같이_보기">같이 보기</h2>
<ul>
<li>{{jsxref("Reflect")}}</li>
<li><a href="/ko/docs/Web/JavaScript/Reference/Operators/Property_Accessors">속성 접근자</a></li>
</ul>
|