prototype
from another object, it also inherits the supertype
's constructor property.
Here's an example:
```js
function Bird() { }
Bird.prototype = Object.create(Animal.prototype);
let duck = new Bird();
duck.constructor // function Animal(){...}
```
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:
```js
Bird.prototype.constructor = Bird;
duck.constructor // function Bird(){...}
```
duck.constructor
and beagle.constructor
return their respective constructors.
Bird.prototype
should be an instance of Animal
.
testString: assert(Animal.prototype.isPrototypeOf(Bird.prototype), 'Bird.prototype
should be an instance of Animal
.');
- text: duck.constructor
should return Bird
.
testString: assert(duck.constructor === Bird, 'duck.constructor
should return Bird
.');
- text: Dog.prototype
should be an instance of Animal
.
testString: assert(Animal.prototype.isPrototypeOf(Dog.prototype), 'Dog.prototype
should be an instance of Animal
.');
- text: beagle.constructor
should return Dog
.
testString: assert(beagle.constructor === Dog, 'beagle.constructor
should return Dog
.');
```