Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
const applyBind = Function.prototype.bind.bind(Function.prototype.apply);
const mapSetApply = applyBind(Map.prototype.set);
const hijackedFns = new Map();
function hijackFunction(context, propName, replacer) {
mapSetApply(hijackedFns, [replacer, context[propName]]);
context[propName] = replacer;
const fnToStringApply = applyBind(Function.prototype.toString);
const mapGetApply = applyBind(Map.prototype.get);
hijackFunction(Function.prototype, 'toString', function toString() {
return fnToStringApply(mapGetApply(hijackedFns, [this]) || this, arguments);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment