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 () {...}
duck.constructor
el código para que duck.constructor
y beagle.constructor
devuelvan sus respectivos constructores. Bird.prototype
debe ser una instancia de Animal
.
testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "Bird.prototype
should be an instance of Animal
.");'
- text: duck.constructor
debe devolver Bird
.
testString: 'assert(duck.constructor === Bird, "duck.constructor
should return Bird
.");'
- text: Dog.prototype
debe ser una instancia de Animal
.
testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "Dog.prototype
should be an instance of Animal
.");'
- text: beagle.constructor
debe devolver el Dog
.
testString: 'assert(beagle.constructor === Dog, "beagle.constructor
should return Dog
.");'
```