Created
November 17, 2018 19:29
-
-
Save JeffML/6110589d2631321675c4a612494397f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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