February 2019
Beginner
694 pages
18h 4m
English
In order to allow for decorators to accept parameters, we need to use what is known as a decorator factory. A decorator factory is simply a wrapper function that returns the decorator function itself. As an example of this, consider the following code:
function decoratorFactory(name: string) {
return function (constructor : Function ) {
console.log(`decorator function called with : ${name}`);
}
}
Here, we have defined a function named decoratorFactory that accepts a single argument, named name, of type string. This function simply returns an anonymous decorator function that takes a single argument named constructor of type Function. The anonymous function (our decorator function) logs the value of the name parameter ...
Read now
Unlock full access