Skip to content

Instantly share code, notes, and snippets.

@madx
Created September 1, 2015 14:30
Show Gist options
  • Save madx/f0cf21a2057a15c7cb90 to your computer and use it in GitHub Desktop.
Save madx/f0cf21a2057a15c7cb90 to your computer and use it in GitHub Desktop.
JavaScript @trace decorator
function trace(target, name, descriptor) {
if (!DEBUG) {
return descriptor
}
const original = descriptor.value
const traced = function(...args) {
console.trace(`${this.constructor.name}#${name}`, args)
return original.call(this, ...args)
}
descriptor.value = traced
return descriptor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment