en.javascript.info/1-js/07-object-inheritance/08-class-patterns/1-inheritance-error-assign/task.md
Ilya Kantor 9ad9063d00 up
2016-11-28 21:35:42 +03:00

441 B

importance: 5


An error in the inheritance

Find an error in the prototypal inheritance below.

What's wrong? What are consequences going to be?

function Animal(name) {
  this.name = name;
}

Animal.prototype.walk = function() {
  alert(this.name + ' walks');
};

function Rabbit(name) {
  this.name = name;
}

Rabbit.prototype = Animal.prototype;

Rabbit.prototype.walk = function() {
  alert(this.name + " bounces!");
};