Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created November 17, 2018 19:29
Show Gist options
  • Save JeffML/6110589d2631321675c4a612494397f1 to your computer and use it in GitHub Desktop.
Save JeffML/6110589d2631321675c4a612494397f1 to your computer and use it in GitHub Desktop.
const log = (target, name, descriptor) => {
/*
target: the class instance of the method
name: the name of the method
descriptor:
value: the method itself
*/
const original = descriptor.value; // hold onto the original function
if (typeof original === 'function') { //ensure that it is a function
// substitute a new function for the original, this is what will be called instead
descriptor.value = function (...args) {
const result = original.apply(this, args); // call the now-wrapped original
console.log(`${name}(${args}) = ${result}`)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment