Problem Statement
How do ES6 classes relate to prototypes under the hood?
Explanation
ES6 class syntax is syntactic sugar over the existing prototype system.
Methods declared in a class body are added to the constructor’s prototype; static methods go on the constructor itself.
Inheritance (extends) sets up the prototype chain between constructors and their prototypes.
Code Solution
SolutionRead Only
class Person { constructor(name){ this.name = name; } greet(){ return 'Hi ' + this.name; } }
class Dev extends Person { code(){ return 'coding'; } }
console.log(Object.getOwnPropertyNames(Person.prototype)); // ['constructor','greet']