aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/referencia/objetos_globales/object/index.html
blob: 99089bd28e2b20f6bdeec6b6574a7b2f50a1c26f (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
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
---
title: Object
slug: Web/JavaScript/Referencia/Objetos_globales/Object
tags:
  - Constructor
  - JavaScript
  - Objeto
  - Referencia
translation_of: Web/JavaScript/Reference/Global_Objects/Object
---
<div>{{JSRef}}</div>

<div>La clase Object representa uno de los tipos de datos de Javascript. Es es usado para guardar una colección de datos definidos y entidades más complejas. Los objetos pueden ser creados utilzando el constructor {{jsxref("Object/Object", "Object()")}} o la sintaxis literal de objeto. </div>

<p>El constructor <code><strong>Object</strong></code> crea una envoltura al objeto.</p>

<h2 id="Sintaxis">Sintaxis</h2>



<pre class="syntaxbox notranslate">// 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="Parámetros">Parámetros</h3>

<dl>
 <dt><code>nameValuePair1, nameValuePair2, ... nameValuePair<em>N</em></code></dt>
 <dd>Los pares de nombres (strings) y los valores (cualquier valor) donde los nombres son separados por una coma.</dd>
 <dt><code>valor</code></dt>
 <dd>Cualquier valor.</dd>
</dl>

<h2 id="Description">Description</h2>

<p>El constructor <code>Object</code> crea una envoltura de objeto  al valor dado.  Si el valor es  {{jsxref("null")}} o {{jsxref("undefined")}}, creará y retornará un objeto vacío, de otra forma, retornará un objeto de un tipo que corresponda al valor dado. Si el valor ya es un objeto devolverá el valor.</p>

<p>Cuando es llamano en un contexto non-constructor, <code>Object </code>se comportará indenticamente a <code>new Object()</code>.</p>

<p>Ver <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">object initializer / literal syntax</a>.</p>

<h2 id="Propiedades_del_constructor_Object">Propiedades del constructor <code>Object</code></h2>

<dl>
 <dt><code>Object.length</code></dt>
 <dd>Tiene un valor de 1.</dd>
 <dt>{{jsxref("Object.prototype")}}</dt>
 <dd>Permite añadir propiedades a todos los objetos del tipo Object.</dd>
</dl>

<h2 id="Métodos_del_constructor_Object">Métodos del constructor  <code>Object</code></h2>

<dl>
 <dt>{{jsxref("Object.assign()")}}</dt>
 <dd>Copia los valores de todas sus propiedades enumerables desde uno o más objetos fuente a un objeto destino.</dd>
 <dt>{{jsxref("Object.create()")}}</dt>
 <dd>Crea un nuevo objeto con el prototipo objeto y propiedades específicadas.</dd>
 <dt>{{jsxref("Object.defineProperty()")}}</dt>
 <dd>Añade la propiedad nombrada descrita por un descriptor dado a un objeto.</dd>
 <dt>{{jsxref("Object.defineProperties()")}}</dt>
 <dd>Agrega las propiedades nombradas descritas por los descriptores dados a un objeto.</dd>
 <dt>{{jsxref("Object.entries()")}}</dt>
 <dd>Returns an array containing all of the <code>[key, value]</code> pairs of a given object's <strong>own</strong> enumerable string properties.</dd>
 <dt>{{jsxref("Object.freeze()")}}</dt>
 <dd>Freezes an object: other code can't delete or change any properties.</dd>
 <dt>{{jsxref("Object.fromEntries()")}}</dt>
 <dd>Returns a new object from an iterable of key-value pairs (reverses {{jsxref("Object.entries")}}).</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 the same value. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison).</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 string 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()")}}</dt>
 <dd>Returns an array containing the values that correspond to all of a given object's <strong>own</strong> enumerable string properties.</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="Deleting_a_property_from_an_object">Deleting a property from an object</h2>

<p>There isn't any method in an Object itself to delete its own properties (e.g. like <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete">Map.prototype.delete()</a></code>). To do so one has to use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete">delete operator</a>.</p>

<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 notranslate">var o = new Object();
</pre>

<pre class="brush: js notranslate">var o = new Object(undefined);
</pre>

<pre class="brush: js notranslate">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 notranslate">// equivalent to o = new Boolean(true);
var o = new Object(true);
</pre>

<pre class="brush: js notranslate">// 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></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>


<p>{{Compat("javascript.builtins.Object")}}</p>
</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>