How do classes relate to prototypes?
A class is a constructor function with a prototype object attached, plus some syntax that makes it stricter and clearer. When you write a class, the engine creates a function for the constructor and puts the methods on its prototype property, exactly the way you would do by hand.
class Greeter {
constructor(name) { this.name = name; }
greet() { return `Hi ${this.name}`; }
}
const greeter = new Greeter("Ada");
console.log(greeter.greet()); // "Hi Ada"
// The class is a constructor function and its methods live on the prototype.
console.log(typeof Greeter); // "function"
console.log(Greeter.prototype.greet instanceof Function); // true
console.log(Object.getPrototypeOf(greeter) === Greeter.prototype); // trueSo an instance still works the way it always has. It has no copy of the methods. It has a link to the class prototype, and reading greet walks that link. The instance check works the same way too, because instanceof compares the prototype chain against the constructor's prototype.
The class syntax adds three things on top of the raw mechanism. The body is always strict mode, so the sloppy-mode surprises with this and with accidental globals are gone. The methods are non-enumerable, which means they do not show up when you iterate the prototype with for...in or with the keys method. And calling a class without the new keyword throws a TypeError instead of running the body with an unexpected this.