Created
September 1, 2015 14:30
-
-
Save madx/f0cf21a2057a15c7cb90 to your computer and use it in GitHub Desktop.
JavaScript @trace decorator
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
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