Skip to content

Instantly share code, notes, and snippets.

@amit08255
Forked from tilmanschweitzer/intercept-function.js
Created August 18, 2022 10:29
Show Gist options
  • Save amit08255/977de656f505f7520cb6dee2a9c3924a to your computer and use it in GitHub Desktop.
Save amit08255/977de656f505f7520cb6dee2a9c3924a 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