--- id: 587d7db1367417b2b2512b86 title: Reset an Inherited Constructor Property challengeType: 1 videoUrl: '' localeTitle: 重置继承的构造函数属性 --- ## Description
当一个对象从另一个对象继承它的prototype ,它也继承了supertype的构造函数属性。这是一个例子:
函数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
修复代码,使duck.constructorbeagle.constructor返回各自的构造函数。
## Tests
```yml tests: - text: Bird.prototype应该是Animal一个实例。 testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "Bird.prototype should be an instance of Animal.");' - text: duck.constructor应该返回Bird 。 testString: 'assert(duck.constructor === Bird, "duck.constructor should return Bird.");' - text: Dog.prototype应该是Animal一个实例。 testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "Dog.prototype should be an instance of Animal.");' - text: beagle.constructor应该返回Dog 。 testString: 'assert(beagle.constructor === Dog, "beagle.constructor should return Dog.");' ```
## Challenge Seed
```js 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
```js // solution required ```