JSFiddle - React, Tailwind, and code Playground
JavaScript
function wrap(oldFn, newFn) {
return function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(oldFn);
return newFn.apply(this, args);
}
}
var obj = {
hello: function () {
return "hello"
}
};
obj.hello = wrap(obj.hello, function (wrappee) {
return wrappee() + " bob";
});
console.log(obj.hello()); // prints "hello bob"