JSFiddle - React, Tailwind, and code Playground

by Michelle Bu

JavaScript

class Vehicle {
	constructor() {
  	console.log('constructing');
  }
  
  start() {
  	console.log('starting')
    this.started = true;
  }
  
  end() {
  	if (!this.started) throw new Error('start the vehicle first')
  	console.log('ending')
  }
}

const props = Object.getOwnPropertyNames(Vehicle.prototype);

const AnotherVehicle = function() {}
AnotherVehicle.prototype = Vehicle.prototype;
props.forEach((prop) => {
	const original = AnotherVehicle.prototype[prop]
	AnotherVehicle.prototype[prop] = function() {
  	console.log('overridden', prop)
  	original.call(this);
  };
})

const v = new AnotherVehicle();
v.start();