-
-
Save felippe-regazio/2c374ec2c93ba13f4ce226e2c5cec1aa 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
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