From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../index.html | 333 +++++++++++++++++++++ 1 file changed, 333 insertions(+) create mode 100644 files/es/web/javascript/enumerability_and_ownership_of_properties/index.html (limited to 'files/es/web/javascript/enumerability_and_ownership_of_properties/index.html') diff --git a/files/es/web/javascript/enumerability_and_ownership_of_properties/index.html b/files/es/web/javascript/enumerability_and_ownership_of_properties/index.html new file mode 100644 index 0000000000..fbe97185f6 --- /dev/null +++ b/files/es/web/javascript/enumerability_and_ownership_of_properties/index.html @@ -0,0 +1,333 @@ +--- +title: Enumerabilidad y posesión de propiedades +slug: Web/JavaScript/enumeracion_y_propietario_de_propiedades +tags: + - Enumerabilidad + - Enumeración + - Guía + - JavaScript + - Propiedades +translation_of: Web/JavaScript/Enumerability_and_ownership_of_properties +--- +
{{JsSidebar("Más")}}
+ +

Las propiedades enumerables son aquellas propiedades cuyo indicador enumerable interno se establece en true, que es el valor predeterminado para las propiedades creadas mediante una asignación simple o mediante un iniciador de propiedad (propiedades definidas mediante {{jsxref("Global_Objects/Object/defineProperty", "Object.defineProperty")}} y tal valor enumerable predeterminado a false). Se muestran numerosas propiedades en bucles {{jsref("Statements/for...in", "for...in")}} a menos que la clave de la propiedad sea {{jsxref("Global_Objects/Symbol", "Symbol")}}. La posesión de las propiedades está determinada por si la propiedad pertenece directamente al objeto y no a su cadena prototipo. Las propiedades de un objeto también se pueden recuperar en total. Hay varios medios incorporados para detectar, iterar/enumerar y recuperar propiedades de objetos, y el gráfico que se muestra a continuación está disponible. A continuación, se muestra un código de muestra que demuestra cómo obtener las categorías faltantes.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Propiedad, enumerabilidad y posesión — métodos integrados de detección, recuperación e iteración
FuncionalidadPropia del ObjetoPropia del Objeto y su cadena prototipoSolo en cadena prototipo
Detección + + + + + + + + + + + + + + + +
EnumerableNo enumerableEnumerable y no enumerable
+

{{jsxref("Global_Objects/Object/propertyIsEnumerable", "propertyIsEnumerable")}}

+ +

{{jsxref("Global_Objects/Object/hasOwnProperty", "hasOwnProperty")}}

+
+

{{jsxref("Global_Objects/Object/hasOwnProperty", "hasOwnProperty")}} — filtrado para excluir enumerables mediante {{jsxref("Global_Objects/Object/propertyIsEnumerable", "propertyIsEnumerable")}}

+
{{jsxref("Global_Objects/Object/hasOwnProperty", "hasOwnProperty")}}
+
+ + + + + + + + + + + + + + + +
EnumerableNo enumerableEnumerable y no enumerable
No disponible sin código adicionalNo disponible sin código adicional{{jsxref("Operators/in", "in")}}
+
No disponible sin código adicional
Recuperación + + + + + + + + + + + + + + + +
EnumerableNo enumerableEnumerable y no enumerable
+

{{jsxref("Global_Objects/Object/keys", "Object.keys")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}}

+
{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}, {{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}} — filtrado para excluir enumerables usando {{jsxref("Global_Objects/Object/propertyIsEnumerable", "propertyIsEnumerable")}} +

{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}}

+
+
No disponible sin código adicionalNo disponible sin código adicional
Iterable + + + + + + + + + + + + + + + +
EnumerableNo enumerableEnumerable y no enumerable
+

{{jsxref("Global_Objects/Object/keys", "Object.keys")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}}

+
{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}, {{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}} — filtrado para excluir enumerables usando {{jsxref("Global_Objects/Object/propertyIsEnumerable", "propertyIsEnumerable")}} +

{{jsxref("Global_Objects/Object/getOwnPropertyNames", "getOwnPropertyNames")}}

+ +

{{jsxref("Global_Objects/Object/getOwnPropertySymbols", "getOwnPropertySymbols")}}

+
+
+ + + + + + + + + + + + + + + +
EnumerableNo enumerableEnumerable y no enumerable
+

{{jsxref("Statements/for...in", "for..in")}}

+ +

(no incluye símbolos)

+
No disponible sin código adicionalNo disponible sin código adicional
+
No disponible sin código adicional
+
+ +

Obtención de propiedades por enumerabilidad/posesión

+ +

Ten en cuenta que este no es el algoritmo más eficiente para todos los casos, pero es útil para una demostración rápida.

+ + + +
var SimplePropertyRetriever = {
+    getOwnEnumerables: function(obj) {
+        return this._getPropertyNames(obj, true, false, this._enumerable);
+         // O podrías usar for..in filtrado con hasOwnProperty o simplemente esto: return Object.keys(obj);
+    },
+    getOwnNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, true, false, this._notEnumerable);
+    },
+    getOwnEnumerablesAndNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, true, false, this._enumerableAndNotEnumerable);
+        // O simplemente usa: return Object.getOwnPropertyNames(obj);
+    },
+    getPrototypeEnumerables: function(obj) {
+        return this._getPropertyNames(obj, false, true, this._enumerable);
+    },
+    getPrototypeNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, false, true, this._notEnumerable);
+    },
+    getPrototypeEnumerablesAndNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, false, true, this._enumerableAndNotEnumerable);
+    },
+    getOwnAndPrototypeEnumerables: function(obj) {
+        return this._getPropertyNames(obj, true, true, this._enumerable);
+        // O podrías usar "for..in" sin filtrar
+    },
+    getOwnAndPrototypeNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, true, true, this._notEnumerable);
+    },
+    getOwnAndPrototypeEnumerablesAndNonenumerables: function(obj) {
+        return this._getPropertyNames(obj, true, true, this._enumerableAndNotEnumerable);
+    },
+    // Retrollamada del supervisor de propiedad estática privada
+    _enumerable: function(obj, prop) {
+        return obj.propertyIsEnumerable(prop);
+    },
+    _notEnumerable: function(obj, prop) {
+        return !obj.propertyIsEnumerable(prop);
+    },
+    _enumerableAndNotEnumerable: function(obj, prop) {
+        return true;
+    },
+    // Inspirado en http://stackoverflow.com/a/8024294/271577
+    _getPropertyNames: function getAllPropertyNames(obj, iterateSelfBool, iteratePrototypeBool, includePropCb) {
+        var props = [];
+
+        do {
+            if (iterateSelfBool) {
+                Object.getOwnPropertyNames(obj).forEach(function(prop) {
+                    if (props.indexOf(prop) === -1 && includePropCb(obj, prop)) {
+                        props.push(prop);
+                    }
+                });
+            }
+            if (!iteratePrototypeBool) {
+                break;
+            }
+            iterateSelfBool = true;
+        } while (obj = Object.getPrototypeOf(obj));
+
+        return props;
+    }
+};
+ +

Tabla de detección

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
infor..inobj.hasOwnPropertyobj.propertyIsEnumerableObject.keysObject.getOwnPropertyNamesObject.getOwnPropertyDescriptorsReflect.ownKeys()
Enumerabletruetruetruetruetruetruetruetrue
No enumerabletruefalsetruefalsefalsetruetruetrue
Símbolos clavetruefalsetruetruefalsefalsetruetrue
Enumerable heredadotruetruefalsefalsefalsefalsefalsefalse
Heredado no enumerabletruefalsefalsefalsefalsefalsefalsefalse
Símbolos clave heredadostruefalsefalsefalsefalsefalsefalsefalse
+
+ +

Ve también

+ + -- cgit v1.2.3-54-g00ecf