2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle |
|---|---|---|---|---|
| 587d7db1367417b2b2512b86 | Reset an Inherited Constructor Property | 1 | Сбросить свойство унаследованного конструктора |
Description
prototype от другого объекта, он также наследует свойство конструктора supertype . Вот пример: function Bird () {}Но
Bird.prototype = Object.create (Animal.prototype);
let duck = new Bird ();
duck.constructor // function Animal () {...}
duck и все случаи Bird должны показать, что они были построены Bird а не Animal . Для этого, вы можете вручную установить Bird's свойство конструктора для Bird объекта: Bird.prototype.constructor = Bird;
duck.constructor // function Bird () {...}
Instructions
undefined
Tests
tests:
- text: ''
testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "<code>Bird.prototype</code> should be an instance of <code>Animal</code>.");'
- text: ''
testString: 'assert(duck.constructor === Bird, "<code>duck.constructor</code> should return <code>Bird</code>.");'
- text: ''
testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "<code>Dog.prototype</code> should be an instance of <code>Animal</code>.");'
- text: ''
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