Created
February 14, 2018 22:26
-
-
Save JeremyRH/795c96c8e488da119e8afeebb7882dd9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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