en.javascript.info/1-js/07-object-oriented-programming/10-class-inheritance/1-class-constructor-error/solution.md
Ilya Kantor 97c8f22bbb up
2017-03-21 17:14:05 +03:00

391 B

That's because the child constructor must call super().

Here's the corrected code:

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