How does this ES6 class syntax relate to prototypal inheritance?
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return `${this.name} makes a noise`;
}
}
class Dog extends Animal {
constructor(name) {
super(name);
}
speak() {
return `${this.name} barks`;
}
}
ES6 classes are syntactic sugar over JavaScript's prototypal inheritance: 1) Under the hood, class syntax still creates constructor functions and prototype chains, 2) Animal.prototype remains the prototype for Dog instances, 3) The extends keyword sets up the prototype chain using Object.create(), 4) super() calls the parent constructor (equivalent to Animal.call(this, name)), 5) Method definitions in the class body are added to the prototype object, 6) instanceof and property lookup still work through the prototype chain. Classes provide a cleaner syntax but don't change JavaScript's core inheritance mechanism.