2.5 KiB
2.5 KiB
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle |
|---|---|---|---|---|
| 587d7db1367417b2b2512b86 | Reset an Inherited Constructor Property | 1 | Restablecer una propiedad de constructor heredada |
Description
prototype de otro objeto, sino que también hereda el supertype propiedad constructor 's. Aquí hay un ejemplo: función Bird () {}Pero el
Bird.prototype = Object.create (Animal.prototype);
dejar pato = nuevo pájaro ();
duck.constructor // function Animal () {...}
duck y todos los casos de Bird deberían mostrar que fueron construidos por Bird y no por Animal . Para hacerlo, puedes establecer manualmente Bird's propiedad Bird's constructor de Bird objeto Bird : Bird.prototype.constructor = Bird;
duck.constructor // function Bird () {...}
Instructions
duck.constructor el código para que duck.constructor y beagle.constructor devuelvan sus respectivos constructores. Tests
tests:
- text: <code>Bird.prototype</code> debe ser una instancia de <code>Animal</code> .
testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "<code>Bird.prototype</code> should be an instance of <code>Animal</code>.");'
- text: <code>duck.constructor</code> debe devolver <code>Bird</code> .
testString: 'assert(duck.constructor === Bird, "<code>duck.constructor</code> should return <code>Bird</code>.");'
- text: <code>Dog.prototype</code> debe ser una instancia de <code>Animal</code> .
testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "<code>Dog.prototype</code> should be an instance of <code>Animal</code>.");'
- text: <code>beagle.constructor</code> debe devolver el <code>Dog</code> .
testString: 'assert(beagle.constructor === Dog, "<code>beagle.constructor</code> should return <code>Dog</code>.");'
Challenge Seed
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Add your code below this line
let duck = new Bird();
let beagle = new Dog();
Solution
// solution required