en.javascript.info/1-js/07-object-inheritance/10-class-inheritance/3-class-extend-object/task.md
Ilya Kantor a7c00e1c76 up
2017-01-18 09:53:11 +01:00

778 B

importance: 5


Class extends Object?

As we know, all objects normally inherit from Object.prototype and get access to "generic" object methods.

Like demonstrated here:

class Rabbit {
  constructor(name) {
    this.name = name;
  }
}

let rabbit = new Rabbit("Rab");

*!*
// hasOwnProperty method is from Object.prototype
// rabbit.__proto__ === Object.prototype
alert( rabbit.hasOwnProperty('name') ); // true
*/!*

So, is it correct to say that "class Rabbit extends Object" does exactly the same as "class Rabbit", or not?

Will it work?

class Rabbit extends Object {
  constructor(name) {
    this.name = name;
  }
}

let rabbit = new Rabbit("Rab");

alert( rabbit.hasOwnProperty('name') ); // true

If it won't please fix the code.