-
-
Save amit08255/977de656f505f7520cb6dee2a9c3924a 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