Created
January 19, 2016 22:02
-
-
Save frontdevops/0691582f88bade60b18a to your computer and use it in GitHub Desktop.
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 log<T>(target: T, key :string, descriptor :any): T { | |
var originalMethod = descriptor.value; | |
descriptor.value = function (...args :any[]) :any { | |
let result = originalMethod.apply(this, args); | |
console.log(`Call: ${key}(${args.map(a=>JSON.stringify(a)).join()}) => ${JSON.stringify(result)}`); | |
return result; | |
}; | |
return descriptor; | |
} | |
class Coffee { | |
protected cost :number = 1.2; | |
@log getCost() :number { return this.cost } | |
@log someDo() { return 'some text' } | |
} | |
let myCoffee = new Coffee; | |
let cost = myCoffee.getCost(); | |
myCoffee.someDo(); | |
/* | |
Output: | |
Call: getCost() => 1.2 | |
Call: someDo() => "some text" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment