A decorator is simply a way of wrapping a function with another function to extend its existing capabilities. You “decorate” your existing code by wrapping it with another piece of code. This concept will not be new to those who are familiar with functional composition or higher-order functions.
Decorators aren’t something new. They have been present in other languages such as Python and even in JavaScript under functional programming. We will speak about this later on.
Decorators allow you to write cleaner code and achieve composition. It also helps you extend the same functionality to several functions and classes. Thereby enabling you to write code that is easier to debug and maintain.
Decorators also allow your code to be less distracting as it removes all the feature enhancing code away from the core function. It also enables you to add features without making your code complex.
Being in the stage 2 proposal, there can be many additions to the class decorator proposal which can be beneficial.
#nodejs #javascript #web-development