Does a super class create a single prototype for ALL subclass instances? I hope not and don’t think so based on the behavior of getWheels()
below:
class Vehicle {
constructor(make, model, wheels) {
this.make = make;
this.model = model;
this.wheels = wheels;
}
getWheels() {
return this.wheels;
}
info() {
return `${this.make} ${this.model}`
}
}
class Car extends Vehicle {
constructor(make, model) {
super(make, model, 4)
}
}
class Motorcycle extends Vehicle {
constructor(make, model) {
super(make, model, 2)
}
}
class Truck extends Vehicle {
constructor(make, model, payload) {
super(make, model, 6);
this.payload = payload;
}
}
const car = new Car("Ford", "Bronco");
const mc = new Motorcycle("Kawasaki", "Ninja");
const mcWheels = mc.getWheels();
console.log(car.getWheels()); // 4
console.log(mc.getWheels()); // 2