JSFiddle - React, Tailwind, and code Playground

by Atty Eleti

JavaScript

wrapFunction = (f) => {
	return function () {
  	console.log('overridden');
    f.apply(this, arguments);
  }
}

wrapClass = (c) => {
	for (let o = c.prototype; o != Object.prototype; o = Object.getPrototypeOf(o)) {
  	const props = Object.getOwnPropertyNames(o);
    props.forEach((prop) => {
      o[prop] = wrapFunction(o[prop]);
    });
  }
  
  return c;
}

class A {
	start() {console.log('starting');}
  end() {console.log('ending');}
}

class B extends A {
	constructor() {super(); this.name = 'B';}
	pause() {console.log('pausing');}
  echo() {console.log('name', this.name)}
}

const WrappedB = wrapClass(B);
const b = new WrappedB();

b.start();
b.end();

b.pause();
b.echo();