en.javascript.info/1-js/9-object-inheritance/10-class-inheritance/2-inheritance-error-constructor/task.md
Ilya Kantor b0976b5253 up
2016-11-14 23:41:18 +03:00

31 lines
577 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

importance: 5
---
# В чём ошибка в наследовании
Найдите ошибку в прототипном наследовании. К чему она приведёт?
```js run
function Animal(name) {
this.name = name;
this.walk = function() {
alert( "ходит " + this.name );
};
}
function Rabbit(name) {
Animal.apply(this, arguments);
}
Rabbit.prototype = Object.create(Animal.prototype);
Rabbit.prototype.walk = function() {
alert( "прыгает " + this.name );
};
var rabbit = new Rabbit("Кроль");
rabbit.walk();
```