Question 46
Question
Answer
const loggingMixin = {
log: function(message) {
console.log(`[${this.constructor.name}] ${message}`);
}
};
class Vehicle {
constructor(brand) {
this.brand = brand;
}
}
class Car extends Vehicle {
constructor(brand, doors) {
super(brand);
this.doors = doors;
}
}
Object.assign(Car.prototype, loggingMixin); // Mix in logging functionality
const myCar = new Car("Toyota", 4);
myCar.log("Starting the engine"); // Output: [Car] Starting the engineLast updated