Factories

Decorator Factories

If we want to customize how a decorator is applied to a declaration, we can write a decorator factory. A Decorator Factory is simply a function that returns the expression that will be called by the decorator at runtime.

We can write a decorator factory in the following fashion:

function color(value: string) { // this is the decorator factory
  return function (target) { // this is the decorator
    // do something with 'target' and 'value'...
  }
}

NOTE You can see a more detailed example of a decorator factory in Method Decorators, below.

doc_TypeScript
2016-10-04 19:25:13
Comments
Leave a Comment

Please login to continue.