Created
September 27, 2017 18:19
-
-
Save jlebensold/19bb02845c311b421b0477e9e389ef06 to your computer and use it in GitHub Desktop.
Logger Decorator
This file contains 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 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