describe
method is shared by Bird
and Dog
:
```js
Bird.prototype = {
constructor: Bird,
describe: function() {
console.log("My name is " + this.name);
}
};
Dog.prototype = {
constructor: Dog,
describe: function() {
console.log("My name is " + this.name);
}
};
```
The describe
method is repeated in two places. The code can be edited to follow the DRY principle by creating a supertype
(or parent) called Animal
:
```js
function Animal() { };
Animal.prototype = {
constructor: Animal,
describe: function() {
console.log("My name is " + this.name);
}
};
```
Since Animal
includes the describe
method, you can remove it from Bird
and Dog
:
```js
Bird.prototype = {
constructor: Bird
};
Dog.prototype = {
constructor: Dog
};
```
eat
method is repeated in both Cat
and Bear
. Edit the code in the spirit of DRY by moving the eat
method to the Animal
supertype
.
Animal.prototype
should have the eat
property.
testString: assert(Animal.prototype.hasOwnProperty('eat'));
- text: Bear.prototype
should not have the eat
property.
testString: assert(!(Bear.prototype.hasOwnProperty('eat')));
- text: Cat.prototype
should not have the eat
property.
testString: assert(!(Cat.prototype.hasOwnProperty('eat')));
```