const Loggable = {
log() { return `[${this.constructor.name}] ${this.toString()}`; }
};
class Base {
toString() { return 'Base instance'; }
}
Object.setPrototypeOf(Base.prototype, Loggable);
class Derived extends Base {
toString() { return 'Derived instance'; }
}
const b = new Base();
const d = new Derived();
console.log(b.log(), d.log(), Object.getPrototypeOf(Derived.prototype) === Base.prototype); Post #3414
2.14K
CHALLENGE
- ❤ 6
- 🔥 2