Skip to content

Instantly share code, notes, and snippets.

@Offirmo
Last active June 21, 2018 00:23
Show Gist options
  • Save Offirmo/03b9352e52d39cf0f37b20f970fe6625 to your computer and use it in GitHub Desktop.
Save Offirmo/03b9352e52d39cf0f37b20f970fe6625 to your computer and use it in GitHub Desktop.
[Function call interception (wrapping)] #JavaScript #growth
// 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