JSFiddle - React, Tailwind, and code Playground
JavaScript
function mySuper() {
return this();
}
function addMethod(object, name, fn) {
object[name] = function() {
var Super = mySuper.bind(object.__proto__[name]);
return fn.apply(object, arguments);
};
}
function Parent() {}
Parent.prototype.foo = function() {
return "FOO";
}
function Child() {
Parent.call(this);
}
Child.prototype = Object.create(Parent.prototype);
var child = new Child();
addMethod(child, 'foo', function() {
return Super() + "BAR";
});
console.log(new Parent());
console.log(child);
console.log(child.foo());