2018-09-30 23:01:58 +01:00
---
id: 587d7db1367417b2b2512b86
title: Reset an Inherited Constructor Property
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301324
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
When an object inherits its `prototype` from another object, it also inherits the supertype's constructor property.
2018-09-30 23:01:58 +01:00
Here's an example:
2019-05-17 06:20:30 -07:00
```js
function Bird() { }
Bird.prototype = Object.create(Animal.prototype);
let duck = new Bird();
duck.constructor // function Animal(){...}
```
2020-11-27 19:02:05 +01:00
But `duck` and all instances of `Bird` should show that they were constructed by `Bird` and not `Animal` . To do so, you can manually set `Bird's` constructor property to the `Bird` object:
2019-05-17 06:20:30 -07:00
```js
Bird.prototype.constructor = Bird;
duck.constructor // function Bird(){...}
```
2020-11-27 19:02:05 +01:00
# --instructions--
Fix the code so `duck.constructor` and `beagle.constructor` return their respective constructors.
# --hints--
`Bird.prototype` should be an instance of `Animal` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(Animal.prototype.isPrototypeOf(Bird.prototype));
```
`duck.constructor` should return `Bird` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(duck.constructor === Bird);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`Dog.prototype` should be an instance of `Animal` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(Animal.prototype.isPrototypeOf(Dog.prototype));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
`beagle.constructor` should return `Dog` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(beagle.constructor === Dog);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
## --seed-contents--
2018-09-30 23:01:58 +01:00
```js
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
2020-03-08 07:46:28 -07:00
// Only change code below this line
2018-09-30 23:01:58 +01:00
let duck = new Bird();
let beagle = new Dog();
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Bird.prototype.constructor = Bird;
let duck = new Bird();
let beagle = new Dog();
```