This is post # 38 of the series, dedicated to exploring JavaScript and its building components. In the process of identifying and describing the core elements, we also share some rules of thumb we use when building SessionStack, a JavaScript application that needs to be robust and high-performing to help companies optimize the digital experience of their users.
Decorators, in a nutshell, involve wrapping a piece of code such as a function or a class with another — a decorator function. The aim is to extend the functionality of the wrapped code without modifying it.
The @ prefix tells the parser that we are using a decorator while the myFnDecorator is the name of the decorator function — a higher-order function.
myFnDecorator takes an argument — decoratedFn which is the decorated function and returns the same function with extended functionality.
From our small contrived example above, we can see that a Python decorator is a higher-order function that takes another function, as an argument and extends it without explicitly modifying it.