Using Decorators

Learn the basics of decorators and see examples of the Angular decorator @Component.

Why decorators?

The Proxy class you have seen so far in this chapter is very useful to synthesize or cook up your own dynamic methods and properties into existing classes. However, sometimes you want to bring a recipe of methods that someone else has created into your own classes and functions. In other words, you want to alter your classes or functions with metadata that, for example, a library or framework expects to find. This is where decorators come in.

Get hands-on with 1200+ tech skills courses.