JSFiddle - React, Tailwind, and code Playground

by saschanaz

HTML

<input id="output" />

JavaScript

function partial(base, extension) {
  extension.prototype.__proto__ = base.prototype.__proto__; // to enable 'super' reference
  const descriptors = Object.getOwnPropertyDescriptors(extension.prototype);
  delete descriptors.constructor; // must not override constructor
  Object.defineProperties(base.prototype, descriptors);
  
  return base;
}

class A {
  foo() {
    return "foo"
  }
}

class B extends A {
  bar() {
    return "bar";
  }
}

partial(B, class {
  foobar() {
    return `${super.foo()}${this.bar()}`;
  }
})

output.value = new B().foobar();