Skip to content

Instantly share code, notes, and snippets.

@saihong
Forked from tilmanschweitzer/intercept-function.js
Created August 15, 2017 02:25
Show Gist options
  • Save saihong/2097260fcb40ab05fadfc2af9db994c1 to your computer and use it in GitHub Desktop.
Save saihong/2097260fcb40ab05fadfc2af9db994c1 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