class Car { constructor(model, year, miles) { this.model = model; this.year = year; this.miles = miles; } toString() { return `${this.model} has done ${this.miles} miles`; } }
↓
class Car { constructor(model, year, miles) { this.model = model; this.year = year; this.miles = miles; } } Car.prototype.toString = function() { return `${this.model} has done ${this.miles} miles`; } }; // ↑すべてのインスタンスで toString を共有するようになる。