aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/object/defineproperties/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/object/defineproperties/index.html')
-rw-r--r--files/es/web/javascript/reference/global_objects/object/defineproperties/index.html194
1 files changed, 194 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/global_objects/object/defineproperties/index.html b/files/es/web/javascript/reference/global_objects/object/defineproperties/index.html
new file mode 100644
index 0000000000..3002dd200d
--- /dev/null
+++ b/files/es/web/javascript/reference/global_objects/object/defineproperties/index.html
@@ -0,0 +1,194 @@
+---
+title: Object.defineProperties()
+slug: Web/JavaScript/Referencia/Objetos_globales/Object/defineProperties
+tags:
+ - ECMAScript5
+ - JavaScript
+ - JavaScript 1.8.5
+ - Método(2)
+ - Objeto
+translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperties
+---
+<div>{{JSRef("Objetos_globales", "Object")}}</div>
+
+<h2 id="Summary" name="Summary">Sumario</h2>
+
+<p>El metodo <strong><code>Object.defineProperties()</code></strong> define nuevas o modifica propiedades existentes directamente en el objeto, retornando el objeto.</p>
+
+<h2 id="Syntax" name="Syntax">Sintáxis</h2>
+
+<pre class="syntaxbox"><code>Object.defineProperties(<em>obj</em>, <em>propiedades</em>)</code></pre>
+
+<h3 id="Parameters" name="Parameters">Parámetros</h3>
+
+<dl>
+ <dt>obj</dt>
+ <dd>El objeto sobre el cual se crearán o modificaran sus propiedades.</dd>
+ <dt>propiedades</dt>
+ <dd>Un objeto cuyas propiedades enumerables propias consituyen descriptores para las propiedades a ser definidas o modificadas.</dd>
+</dl>
+
+<h2 id="Description" name="Description">Descripción</h2>
+
+<p><code>Object.defineProperties</code>, en escencia, define todas las propiedades correspondientes a las propiedades propias con capacidad de enumeración de <code>props</code> en el objeto <code>objrops.</code></p>
+
+<h2 id="Ejemplo">Ejemplo</h2>
+
+<pre class="brush: js">Object.defineProperties(obj, {
+ "property1": {
+ value: true,
+ writable: true
+ },
+ "property2": {
+ value: "Hello",
+ writable: false
+ }
+ // etc. etc.
+});</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<p>Asumiendo una ejecución pristina del entorno con todos los nombres y propiedades referidas a sus valores iniciales, <code>Object.defineProperties</code> es casi completamente equivalente (note el comentario en <code>isCallable</code>) a la siguiente reimplementación de JavaScript:</p>
+
+<pre class="brush: js;highlight:[8]">function defineProperties(obj, properties) {
+ function convertToDescriptor(desc) {
+ function hasProperty(obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop);
+ }
+
+ function isCallable(v) {
+ // NB: modify as necessary if other values than functions are callable.
+ return typeof v === "function";
+ }
+
+ if (typeof desc !== "object" || desc === null)
+ throw new TypeError("bad desc");
+
+ var d = {};
+
+ if (hasProperty(desc, "enumerable"))
+ d.enumerable = !!obj.enumerable;
+ if (hasProperty(desc, "configurable"))
+ d.configurable = !!obj.configurable;
+ if (hasProperty(desc, "value"))
+ d.value = obj.value;
+ if (hasProperty(desc, "writable"))
+ d.writable = !!desc.writable;
+ if ( hasProperty(desc, "get") ) {
+ var g = desc.get;
+
+ if (!isCallable(g) &amp;&amp; g !== "undefined")
+ throw new TypeError("bad get");
+ d.get = g;
+ }
+ if ( hasProperty(desc, "set") ) {
+ var s = desc.set;
+ if (!isCallable(s) &amp;&amp; s !== "undefined")
+ throw new TypeError("bad set");
+ d.set = s;
+ }
+
+ if (("get" in d || "set" in d) &amp;&amp; ("value" in d || "writable" in d))
+ throw new TypeError("identity-confused descriptor");
+
+ return d;
+ }
+
+ if (typeof obj !== "object" || obj === null)
+ throw new TypeError("bad obj");
+
+ properties = Object(properties);
+
+ var keys = Object.keys(properties);
+ var descs = [];
+
+ for (var i = 0; i &lt; keys.length; i++)
+ descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
+
+ for (var i = 0; i &lt; descs.length; i++)
+ Object.defineProperty(obj, descs[i][0], descs[i][1]);
+
+ return obj;
+}</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">Comentario</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.2.3.7', 'Object.defineProperties')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td>Definición inicial. Implementada en JavaScript 1.8.5</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-object.defineproperties', 'Object.defineProperties')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilidad de navegadores</h2>
+
+<p>Basado en <a class="external" href="http://kangax.github.com/es5-compat-table/">Kangax's compat tables</a>.</p>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Caracteristica</th>
+ <th>Firefox (Gecko)</th>
+ <th>Chrome</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Soporte básico</td>
+ <td>{{CompatGeckoDesktop("2")}}</td>
+ <td>5 (previous versions untested)</td>
+ <td>9</td>
+ <td>11.60</td>
+ <td>5</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Caracteristica</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Android</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Soporte básico</td>
+ <td>{{CompatGeckoMobile("2")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>11.50</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also" name="See_also">Ver también</h2>
+
+<ul>
+ <li>{{jsxref("Object.defineProperty()")}}</li>
+ <li>{{jsxref("Object.keys()")}}</li>
+ <li><a href="/en-US/docs/Enumerability_and_ownership_of_properties" title="Enumerability_and_ownership_of_properties">Enumerability and ownership of properties</a></li>
+</ul>