Created
November 17, 2018 20:00
-
-
Save JeffML/92a0340bbb558df1778c77b2382ba4dc 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 insertStuff = (target, name, descriptor) => { | |
const original = descriptor.value; | |
if (typeof original === 'function') { | |
const paramNames = getParamNames(original) | |
descriptor.value = function () { | |
const args = paramNames.reduce((arr, pn, i) => { | |
arr[i] = this.newStuff[pn]; | |
return arr;}, [] ) | |
const result = original.apply(this, [...args]); | |
// console.log(`${name}(${JSON.stringify(args)}) = ${result}`) | |
} | |
} | |
} | |
class MyClass { | |
@insertStuff | |
getStuff(isWombat, sugar) { | |
console.log({isWombat, sugar}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment