Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1125027 of Object

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Object
  • Revision title: Object
  • Revision id: 1125027
  • Created:
  • Creator: Natalya_Surikova
  • Is current revision? Yes
  • Comment I changed nothing, but I feel that "Compares if two values are distinguishable (ie. the same)" is not correct because 1) two values can be either distinguishable or the same 2) the word "Compares" should be replaced by the word "Determines"

Revision Content

{{JSRef}}

The Object constructor creates an object wrapper.

Syntax

// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }

// Called as a constructor
new Object([value])

Parameters

nameValuePair1, nameValuePair2, ... nameValuePairN
Pairs of names (strings) and values (any value) where the name is separated from the value by a colon.
value
Any value.

Description

The Object constructor creates an object wrapper for the given value. If the value is {{jsxref("null")}} or {{jsxref("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.

When called in a non-constructor context, Object behaves identically to new Object().

See also the object initializer / literal syntax.

Properties of the Object constructor

Object.length
Has a value of 1.
{{jsxref("Object.prototype")}}
Allows the addition of properties to all objects of type Object.

Methods of the Object constructor

{{jsxref("Object.assign()")}}
Creates a new object by copying the values of all enumerable own properties from one or more source objects to a target object.
{{jsxref("Object.create()")}}
Creates a new object with the specified prototype object and properties.
{{jsxref("Object.defineProperty()")}}
Adds the named property described by a given descriptor to an object.
{{jsxref("Object.defineProperties()")}}
Adds the named properties described by the given descriptors to an object.
{{jsxref("Object.entries()")}} {{experimental_inline}}
Returns an array of a given object's own enumerable property [key, value] pairs.
{{jsxref("Object.freeze()")}}
Freezes an object: other code can't delete or change any properties.
{{jsxref("Object.getOwnPropertyDescriptor()")}}
Returns a property descriptor for a named property on an object.
{{jsxref("Object.getOwnPropertyDescriptors()")}}
Returns an object containing all own property descriptors for an object.
{{jsxref("Object.getOwnPropertyNames()")}}
Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.
{{jsxref("Object.getOwnPropertySymbols()")}}
Returns an array of all symbol properties found directly upon a given object.
{{jsxref("Object.getPrototypeOf()")}}
Returns the prototype of the specified object.
{{jsxref("Object.is()")}}
Compares if two values are distinguishable (ie. the same)
{{jsxref("Object.isExtensible()")}}
Determines if extending of an object is allowed.
{{jsxref("Object.isFrozen()")}}
Determines if an object was frozen.
{{jsxref("Object.isSealed()")}}
Determines if an object is sealed.
{{jsxref("Object.keys()")}}
Returns an array containing the names of all of the given object's own enumerable properties.
{{jsxref("Object.preventExtensions()")}}
Prevents any extensions of an object.
{{jsxref("Object.seal()")}}
Prevents other code from deleting properties of an object.
{{jsxref("Object.setPrototypeOf()")}}
Sets the prototype (i.e., the internal [[Prototype]] property)
{{jsxref("Object.values()")}} {{experimental_inline}}
Returns an array of a given object's own enumerable values.

Object instances and Object prototype object

All objects in JavaScript are descended from Object; all objects inherit methods and properties from {{jsxref("Object.prototype")}}, although they may be overridden. For example, other constructors' prototypes override the constructor property and provide their own toString() methods. Changes to the Object prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.

Properties

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}

Methods

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}

Examples

Using Object given undefined and null types

The following examples store an empty Object object in o:

var o = new Object();
var o = new Object(undefined);
var o = new Object(null);

Using Object to create Boolean objects

The following examples store {{jsxref("Boolean")}} objects in o:

// equivalent to o = new Boolean(true);
var o = new Object(true);
// equivalent to o = new Boolean(false);
var o = new Object(Boolean());

Specifications

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Initial definition. Implemented in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.2', 'Object')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-object-objects', 'Object')}} {{Spec2('ES6')}} Added Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf, Object.is
{{SpecName('ESDraft', '#sec-object-objects', 'Object')}} {{Spec2('ESDraft')}} Added Object.entries, Object.values and Object.getOwnPropertyDescriptors.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

See also

Revision Source

<div>{{JSRef}}</div>

<p>The <code><strong>Object</strong></code> constructor creates an object wrapper.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
// Object initialiser or literal
{ [ <var>nameValuePair1</var>[, <var>nameValuePair2</var>[, ...<var>nameValuePairN</var>] ] ] }

// Called as a constructor
new Object([<var>value</var>])</pre>

<h3 id="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">Description</h2>

<p>The <code>Object</code> constructor creates an object wrapper for the given value. If the value is {{jsxref("null")}} or {{jsxref("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_of_the_Object_constructor">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_of_the_Object_constructor">Methods of the <code>Object</code> constructor</h2>

<dl>
 <dt>{{jsxref("Object.assign()")}}</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.entries()")}} {{experimental_inline}}</dt>
 <dd>Returns an array of a given object's own enumerable property <code>[key, value]</code> pairs.</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.getOwnPropertyDescriptors()")}}</dt>
 <dd>Returns an object containing all own property descriptors for 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()")}}</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()")}}</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.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()")}}</dt>
 <dd>Sets the prototype (i.e., the internal <code>[[Prototype]]</code> property)</dd>
 <dt>{{jsxref("Object.values()")}} {{experimental_inline}}</dt>
 <dd>Returns an array of a given object's own enumerable values.</dd>
</dl>

<h2 id="Object_instances_and_Object_prototype_object"><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">Properties</h3>

<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}</div>

<h3 id="Methods">Methods</h3>

<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}</div>

<h2 id="Examples">Examples</h2>

<h3 id="Using_Object_given_undefined_and_null_types">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="Using_Object_to_create_Boolean_objects">Using <code>Object</code> to create <code>Boolean</code> objects</h3>

<p>The following examples store {{jsxref("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>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</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>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-object-objects', 'Object')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Added Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf, Object.is</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-object-objects', 'Object')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Added Object.entries, Object.values and Object.getOwnPropertyDescriptors.</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">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">Object initializer</a></li>
</ul>
Revert to this revision