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

27 lines
391 B
Markdown

That's because the child constructor must call `super()`.
Here's the corrected code:
```js run
class Animal {
constructor(name) {
this.name = name;
}
}
class Rabbit extends Animal {
constructor(name) {
*!*
super(name);
*/!*
this.created = Date.now();
}
}
*!*
let rabbit = new Rabbit("White Rabbit"); // ok now
*/!*
alert(rabbit.name); // White Rabbit
```