-
-
Save cvazac/ebc544d12dbf58f51ab082810db0cab3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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