aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/javascript/reference/global_objects/reflect/set/index.html
blob: 45022b89d1edac123f5ed3a06a78bd35766af31d (plain)
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
---
title: Reflect.set()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/set
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/set
---
<div>{{JSRef}}</div>

<p>O método estático <code><strong>Reflect</strong></code><strong><code>.set()</code></strong> define uma propriedade em um objeto.</p>

<h2 id="Sintaxe">Sintaxe</h2>

<pre class="syntaxbox">Reflect.set(alvo, propriedade, valor[, receptor])
</pre>

<h3 id="Parâmetros">Parâmetros</h3>

<dl>
 <dt><code>alvo</code></dt>
 <dd>O objeto alvo onde a propriedade será definida.</dd>
 <dt><code>propriedade</code></dt>
 <dd>O nome da propriedade a ser definida.</dd>
 <dt>valor</dt>
 <dd>o valor a ser definido para a propriedade.</dd>
 <dt>receptor</dt>
 <dd>
 <p>O valor do <code>this </code>fornecido para a chamada do alvo se um setter é encontrado.</p>
 </dd>
</dl>

<h3 id="Retorno">Retorno</h3>

<p>Um {{jsxref("Boolean")}} indicando se a definicão da propriedade ocorreu com sucesso ou não.</p>

<h3 id="Exceções">Exceções</h3>

<p>Um {{jsxref("TypeError")}}, se o <code>alvo</code> não for um {{jsxref("Object")}}.</p>

<h2 id="Descrição">Descrição</h2>

<p>O método <code>Reflect.set</code> permite que você defina uma propriedade em um objeto. Ele define a propriedade e is like the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">property accessor</a> syntax as a function.</p>

<h2 id="Examplos">Examplos</h2>

<h3 id="Usando_Reflect.set()">Usando <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"

// É possível truncar o array
Reflect.set(arr, "length", 1); // true
arr; // ["duck"];

// Com apenas um argumento, propertKey e valor são undefined
var obj = {};
Reflect.set(obj); // true
Reflect.getOwnPropertyDescriptor(obj, "undefined");
// { value: undefined, writable: true, enumerable: true, configurable: true }
</pre>

<h2 id="Especificações">Especificações</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('ES6', '#sec-reflect.set', 'Reflect.set')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Definição inicial.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-reflect.set', 'Reflect.set')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Compatilibidade_com_navegadores">Compatilibidade com navegadores</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>49</td>
   <td>{{CompatGeckoDesktop(42)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile(42)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Veja_também">Veja também</h2>

<ul>
 <li>{{jsxref("Reflect")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors">Property accessors</a></li>
</ul>