JSFiddle - React, Tailwind, and code Playground

by Atty Eleti

JavaScript

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

wrapClass = (c) => {
	const wrapper = () => {};
  wrapper.prototype = c.prototype;
  
  const props = Object.getOwnPropertyNames(wrapper.prototype);
  props.forEach((prop) => {
  	wrapper.prototype[prop] = wrapFunction(wrapper.prototype, wrapper.prototype[prop]);
  })
  
  return wrapper;
}

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

class B extends A {
	pause() {console.log('pausing');}
}

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

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

b.pause();