Skip to content

Instantly share code, notes, and snippets.

@jlebensold
Created September 27, 2017 18:19
Show Gist options
  • Save jlebensold/19bb02845c311b421b0477e9e389ef06 to your computer and use it in GitHub Desktop.
Save jlebensold/19bb02845c311b421b0477e9e389ef06 to your computer and use it in GitHub Desktop.
Logger Decorator
function logger() {
return function (target, key, descriptor) {
const initialValue = descriptor.value;
descriptor.value = function() {
console.log(`>"${key}" with`, arguments);
return initialValue.apply(null, arguments);
};
return descriptor;
}
}
class MyText {
@logger()
isProcessing() {
return [1,2,3,4,5]
}
@logger()
isCalculating(values) {
return values.map((v) => v + v )
}
render() {
const output = this.isProcessing();
const result = this.isCalculating(output);
console.log(result);
}
}
myText = new MyText()
myText.render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment