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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
---
title: Object
slug: Web/JavaScript/Reference/Global_Objects/Object
tags:
- Constructor
- JavaScript
- NeedsTranslation
- Object
- TopicStub
translation_of: Web/JavaScript/Reference/Global_Objects/Object
---
<div>{{JSRef}}</div>
<p>The <code><strong>Object</strong></code> constructor creates an object wrapper.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><code>// Object initialiser or literal
{ [ <var>nameValuePair1</var>[, <var>nameValuePair2</var>[, ...<var>nameValuePairN</var>] ] ] }
// Called as a constructor
new Object([<var>value</var>])</code></pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
<dt><code>nameValuePair1, nameValuePair2, ... nameValuePair<em>N</em></code></dt>
<dd>Pairs of names (strings) and values (any value) where the name is separated from the value by a colon.</dd>
<dt><code>value</code></dt>
<dd>Any value.</dd>
</dl>
<h2 id="Description" name="Description">Description</h2>
<p>The <code>Object</code> constructor creates an object wrapper for the given value. If the value is {{jsxref("Global_Objects/null", "null")}} or {{jsxref("Global_Objects/undefined", "undefined")}}, it will create and return an empty object, otherwise, it will return an object of a Type that corresponds to the given value. If the value is an object already, it will return the value.</p>
<p>When called in a non-constructor context, <code>Object</code> behaves identically to <code>new Object()</code>.</p>
<p>See also the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">object initializer / literal syntax</a>.</p>
<h2 id="Properties" name="Properties">Properties of the <code>Object</code> constructor</h2>
<dl>
<dt><code>Object.length</code></dt>
<dd>Has a value of 1.</dd>
<dt>{{jsxref("Object.prototype")}}</dt>
<dd>Allows the addition of properties to all objects of type Object.</dd>
</dl>
<h2 id="Methods" name="Methods">Methods of the <code>Object</code> constructor</h2>
<dl>
<dt>{{jsxref("Object.assign()")}} {{experimental_inline}}</dt>
<dd>Creates a new object by copying the values of all enumerable own properties from one or more source objects to a target object.</dd>
<dt>{{jsxref("Object.create()")}}</dt>
<dd>Creates a new object with the specified prototype object and properties.</dd>
<dt>{{jsxref("Object.defineProperty()")}}</dt>
<dd>Adds the named property described by a given descriptor to an object.</dd>
<dt>{{jsxref("Object.defineProperties()")}}</dt>
<dd>Adds the named properties described by the given descriptors to an object.</dd>
<dt>{{jsxref("Object.freeze()")}}</dt>
<dd>Freezes an object: other code can't delete or change any properties.</dd>
<dt>{{jsxref("Object.getOwnPropertyDescriptor()")}}</dt>
<dd>Returns a property descriptor for a named property on an object.</dd>
<dt>{{jsxref("Object.getOwnPropertyNames()")}}</dt>
<dd>Returns an array containing the names of all of the given object's <strong>own</strong> enumerable and non-enumerable properties.</dd>
<dt>{{jsxref("Object.getOwnPropertySymbols()")}} {{ experimental_inline() }}</dt>
<dd>Returns an array of all symbol properties found directly upon a given object.</dd>
<dt>{{jsxref("Object.getPrototypeOf()")}}</dt>
<dd>Returns the prototype of the specified object.</dd>
<dt>{{jsxref("Object.is()")}} {{ experimental_inline() }}</dt>
<dd>Compares if two values are distinguishable (ie. the same)</dd>
<dt>{{jsxref("Object.isExtensible()")}}</dt>
<dd>Determines if extending of an object is allowed.</dd>
<dt>{{jsxref("Object.isFrozen()")}}</dt>
<dd>Determines if an object was frozen.</dd>
<dt>{{jsxref("Object.isSealed()")}}</dt>
<dd>Determines if an object is sealed.</dd>
<dt>{{jsxref("Object.keys()")}}</dt>
<dd>Returns an array containing the names of all of the given object's <strong>own</strong> enumerable properties.</dd>
<dt>{{jsxref("Object.observe()")}} {{experimental_inline}}</dt>
<dd>Asynchronously observes changes to an object.</dd>
<dt>{{jsxref("Object.preventExtensions()")}}</dt>
<dd>Prevents any extensions of an object.</dd>
<dt>{{jsxref("Object.seal()")}}</dt>
<dd>Prevents other code from deleting properties of an object.</dd>
<dt>{{jsxref("Object.setPrototypeOf()")}} {{experimental_inline}}</dt>
<dd>Sets the prototype (i.e., the internal <code>[[Prototype]]</code> property)</dd>
</dl>
<h2 id="Object_instances" name="Object_instances"><code>Object</code> instances and <code>Object</code> prototype object</h2>
<p>All objects in JavaScript are descended from <code>Object</code>; all objects inherit methods and properties from {{jsxref("Object.prototype")}}, although they may be overridden. For example, other constructors' prototypes override the <code>constructor</code> property and provide their own <code>toString()</code> methods. Changes to the <code>Object</code> prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.</p>
<h3 id="Properties_of_Object_instances" name="Properties_of_Object_instances">Properties</h3>
<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}</div>
<h3 id="Methods_of_Object_instances" name="Methods_of_Object_instances">Methods</h3>
<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}</div>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example.3A_Using_Object_given_undefined_and_null_types" name="Example.3A_Using_Object_given_undefined_and_null_types">Example: Using <code>Object</code> given <code>undefined</code> and <code>null</code> types</h3>
<p>The following examples store an empty <code>Object</code> object in <code>o</code>:</p>
<pre class="brush: js">var o = new Object();
</pre>
<pre class="brush: js">var o = new Object(undefined);
</pre>
<pre class="brush: js">var o = new Object(null);
</pre>
<h3 id="Example_Using_Object_to_create_Boolean_objects">Example: Using <code>Object</code> to create <code>Boolean</code> objects</h3>
<p>The following examples store {{jsxref("Global_Objects/Boolean", "Boolean")}} objects in <code>o</code>:</p>
<pre class="brush: js">// equivalent to o = new Boolean(true);
var o = new Object(true);
</pre>
<pre class="brush: js">// equivalent to o = new Boolean(false);
var o = new Object(Boolean());
</pre>
<h2 id="Specifications">Specifications</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>ECMAScript 1st Edition.</td>
<td>Standard</td>
<td>Initial definition. Implemented in JavaScript 1.0.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.2', 'Object')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-object-objects', 'Object')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{CompatibilityTable}}</div>
<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>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</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>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">Object initializer</a></li>
</ul>
|