freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../object-oriented-programming/iterate-over-all-properties...

2.6 KiB

id title challengeType videoUrl localeTitle
587d7daf367417b2b2512b7d Iterate Over All Properties 1 Iterar sobre todas las propiedades

Description

Ahora ha visto dos tipos de propiedades: propiedades own y propiedades prototype . Own propiedades Own se definen directamente en la instancia del objeto en sí. Y las propiedades del prototype se definen en el prototype .
función Bird (nombre) {
this.name = nombre; //propia propiedad
}

Bird.prototype.numLegs = 2; // propiedad prototipo

dejar pato = nuevo pájaro ("Donald");
Aquí es cómo se agregan las propiedades own duck a la matriz ownProps y las propiedades de prototype a la matriz prototypeProps :
dejemos ownProps = [];
vamos prototypeProps = [];

para (dejar propiedad en pato) {
if (duck.hasOwnProperty (propiedad)) {
ownProps.push (propiedad);
} else {
prototypeProps.push (propiedad);
}
}

console.log (ownProps); // imprime ["nombre"]
console.log (prototypeProps); // imprime ["numLegs"]

Instructions

Agregue todas las propiedades own de beagle a la matriz ownProps . Agregue todas las propiedades prototype de Dog a la matriz prototypeProps .

Tests

tests:
  - text: La matriz <code>ownProps</code> debe incluir <code>&quot;name&quot;</code> .
    testString: 'assert(ownProps.indexOf("name") !== -1, "The <code>ownProps</code> array should include <code>"name"</code>.");'
  - text: La matriz <code>prototypeProps</code> debe incluir <code>&quot;numLegs&quot;</code> .
    testString: 'assert(prototypeProps.indexOf("numLegs") !== -1, "The <code>prototypeProps</code> array should include <code>"numLegs"</code>.");'
  - text: Resuelva este desafío sin usar el método <code>Object.keys()</code> .
    testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method <code>Object.keys()</code>.");'

Challenge Seed

function Dog(name) {
  this.name = name;
}

Dog.prototype.numLegs = 4;

let beagle = new Dog("Snoopy");

let ownProps = [];
let prototypeProps = [];

// Add your code below this line

Solution

// solution required