Last active
June 21, 2018 00:23
-
-
Save Offirmo/03b9352e52d39cf0f37b20f970fe6625 to your computer and use it in GitHub Desktop.
[Function call interception (wrapping)] #JavaScript #growth
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
// new | |
return (...args) => { | |
try { | |
return handler.call(this, ...args); | |
} catch(e) { | |
return this.onError(e); | |
} | |
}; | |
// old school | |
const originalFunc = foo.XXX; | |
foo.XXX = function () { | |
return originalFunc.apply(foo, arguments); | |
}; | |
// see also: | |
// http://2ality.com/2015/10/intercepting-method-calls.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment