Skip to content

Instantly share code, notes, and snippets.

@JeremyRH
Created February 14, 2018 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeremyRH/795c96c8e488da119e8afeebb7882dd9 to your computer and use it in GitHub Desktop.
Save JeremyRH/795c96c8e488da119e8afeebb7882dd9 to your computer and use it in GitHub Desktop.
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