Forked from tilmanschweitzer/intercept-function.js
Last active
December 11, 2021 12:39
-
-
Save qb20nh/50f15c14e3b90c666adead1d55c41d32 to your computer and use it in GitHub Desktop.
Function to intercept functions calls even to nativ functions.
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 interceptFunction = (object, fnName, options) => { | |
const noop = () => {} | |
const fnToWrap = object[fnName] | |
const before = options.before || noop | |
const after = options.after || noop | |
object[fnName] = function (...args) { | |
before.apply(this, args) | |
const result = fnToWrap.apply(this, args) | |
after.apply(this, args, result) | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment