July 2017
Intermediate to advanced
454 pages
10h 1m
English
Method decorators are declared before the method declaration. This decorator is used to modify, observe, or replace a method definition and is applied to the property descriptor for the method. The following code snippet shows a simple class with an applied method decorator:
class Hello {
@logging
increment(n: number) {
return n++;
}
}
The Hello class has the increment method that increments a number supplied to its parameter. Note that the increment method is decorated with the @logging decorator to log input and output of the increment method. The following is the code snippet of the logging function:
function logging(target: Object, key: string, value: any) { value.value = function (...args: any[]) { var result = value.apply(this, ...Read now
Unlock full access