Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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