Types of Decorators

Learn about the different types of decorators in JavaScript and their use cases.

Introduction to decorator types

Decorators are functions that are invoked by the JavaScript runtime when a class is defined. Depending on what type of decorator is used, these decorator functions will be invoked with different arguments.

Let’s take a quick look at the types of decorators, which are:

  • Class decorators: These are decorators that can be applied to a class definition.

  • Property decorators: These are decorators that can be applied to a property within a class.

  • Method decorators: These are decorators that can be applied to a method on a class.

  • Parameter decorators: These are decorators that can be applied to a parameter of a method within a class.

As an example of these types of decorators, consider the following code:

Get hands-on with 1200+ tech skills courses.