Skip to content

Instantly share code, notes, and snippets.

@whjvenyl
Forked from tilmanschweitzer/intercept-function.js
Created April 26, 2017 13:18
Show Gist options
  • Save whjvenyl/fa02d4cc1e90113f09fb9dc432b6135d to your computer and use it in GitHub Desktop.
Save whjvenyl/fa02d4cc1e90113f09fb9dc432b6135d 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