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) {Aquí es cómo se agregan las propiedades
this.name = nombre; //propia propiedad
}
Bird.prototype.numLegs = 2; // propiedad prototipo
dejar pato = nuevo pájaro ("Donald");
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"]
own de beagle a la matriz ownProps . Agregue todas las propiedades prototype de Dog a la matriz prototypeProps . ownProps debe incluir "name" .
testString: 'assert(ownProps.indexOf("name") !== -1, "The ownProps array should include "name".");'
- text: La matriz prototypeProps debe incluir "numLegs" .
testString: 'assert(prototypeProps.indexOf("numLegs") !== -1, "The prototypeProps array should include "numLegs".");'
- text: Resuelva este desafío sin usar el método Object.keys() .
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method Object.keys().");'
```