Skip to content

Instantly share code, notes, and snippets.

@tilmanschweitzer
Last active September 23, 2022 18:25
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save tilmanschweitzer/8549286 to your computer and use it in GitHub Desktop.
Save tilmanschweitzer/8549286 to your computer and use it in GitHub Desktop.
Function to intercept functions calls even to nativ functions.
function interceptFunction (object, fnName, options) {
var noop = function () {};
var fnToWrap = object[fnName];
var before = options.before || noop;
var after = options.after || noop;
object[fnName] = function () {
before.apply(this, arguments);
var result = fnToWrap.apply(this, arguments);
after.apply(this, arguments);
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment