JSFiddle - React, Tailwind, and code Playground
by toddmotto
JavaScript
// function definition
function normal(text) {
// log out `text` which will be passed in when hijacked
document.body.innerHTML += 'Normal:::' + text;
}
// assign the function without calling it
var hijacked = normal;
// define a new "normal" function
normal = function () {
// run your logic needed before the hijacking
document.body.innerHTML += 'Hijacked!';
// execute the function, the key here is using .apply() to
// call the function, which then passes in all the `arguments`
// as if they were called "naturally" without hijacking
hijacked.apply(hijacked, arguments);
};
// call the `normal` function as normal, pass your arguments
// into the function as normal
normal('Some text here!');