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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
---
title: Reflect.set()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/set
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/set
---
<div>{{JSRef}}</div>
<p>El método estático <code><strong>Reflect</strong></code><strong><code>.set()</code></strong> funciona igual que asignar una propiedad en un objeto.</p>
<h2 id="Sintaxis">Sintaxis</h2>
<pre class="syntaxbox">Reflect.set(target, propertyKey, value[, receiver])
</pre>
<h3 id="Parámetros">Parámetros</h3>
<dl>
<dt><code>target</code></dt>
<dd>El objeto en el cual se va a asignar una propiedad.</dd>
<dt><code>propertyKey</code></dt>
<dd>El nombre de la propiedad a asignar.</dd>
<dt>value</dt>
<dd>El valor de la propiedad.</dd>
<dt>receiver</dt>
<dd>El valor de <code>this</code> para usar en la llamada a <code>target</code> si se encuentra un setter.</dd>
</dl>
<h3 id="Valor_de_retorno">Valor de retorno</h3>
<p>Un {{jsxref("Boolean")}} indicando si se pudo o no asignar la propiedad.</p>
<h3 id="Excepciones">Excepciones</h3>
<p>Un {{jsxref("TypeError")}}, si <code>target</code> no es un {{jsxref("Object")}}.</p>
<h2 id="Descripción">Descripción</h2>
<p>El método <code>Reflect.set</code> permite asignar una propiedad a un objeto. It does property assignment and is like the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">property accessor</a> syntax as a function.</p>
<h2 id="Ejemplos">Ejemplos</h2>
<h3 id="Uso_de_Reflect.set()"><code><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif">Uso de </font>Reflect.set()</code></h3>
<pre class="brush: js">// Objeto
var obj = {};
Reflect.set(obj, 'prop', 'value'); // true
obj.prop; // "value"
// Arreglo
var arr = ['duck', 'duck', 'duck'];
Reflect.set(arr, 2, 'goose'); // true
arr[2]; // "goose"
// Puede truncar un arreglo.
Reflect.set(arr, 'length', 1); // true
arr; // ["duck"];
// Con solo un argumento, propertyKey y value son "undefined".
var obj = {};
Reflect.set(obj); // true
Reflect.getOwnPropertyDescriptor(obj, 'undefined');
// { value: undefined, writable: true, enumerable: true, configurable: true }
</pre>
<h2 id="Especificaciones">Especificaciones</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Especificación</th>
<th scope="col">Estado</th>
<th scope="col">Comentarios</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="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Característica</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Soporte básico</td>
<td>49</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop(42)}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>10</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Característica</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Soporte básico</td>
<td>{{CompatNo}}</td>
<td>49</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile(42)}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>10</td>
</tr>
</tbody>
</table>
</div>
<h2 id="Ver_también">Ver también</h2>
<ul>
<li>{{jsxref("Reflect")}}</li>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">Property accessors</a></li>
</ul>
|