December 2017
Beginner
372 pages
10h 32m
English
Our previous example was good enough to show how to create decorators in TypeScript; now let's add some flexibility to our decorator. TypeScript defines a concept of the decorator factory that we saw earlier that allows us to pass custom values to our decorator and use them in processing. This feature is extremely necessary because we would want our decorators to be able to execute based on various criterions defined by the class.
The following is the refactored code for our logger decorator, which takes one parameter as a name:
//Decorator Definitionfunction logger (name:string) { return function(target:Function){ console.log ('Class is: ${name}'); }}
In this case, we wrap our decorator function inside ...
Read now
Unlock full access