Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created November 17, 2018 20:00
Show Gist options
  • Save JeffML/92a0340bbb558df1778c77b2382ba4dc to your computer and use it in GitHub Desktop.
Save JeffML/92a0340bbb558df1778c77b2382ba4dc to your computer and use it in GitHub Desktop.
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