This is what decorators look like written in Python:

Example taken from Wikipedia. (Link)

def viking_chorus(myfunc):

def inner_func(*args, **kwargs):

for i in range(8):

myfunc(*args, **kwargs)

return inner_func @viking_chorus

def menu_item():

print("spam")

Don’t think too much about the code if you’re not into Python. The only interesting part up there for us is the ‘@viking_chorus’

The above code translates to:

def menu_item():

print("spam")

menu_item = viking_chorus(menu_item)

As you can see the decorator is basically just a cool kid’s way of calling higher-order functions, which is beyond easy in JavaScript, although if not used correctly can get quite ugly.

JavaScript isn’t trying to tackle this non-problem instead it’s setting its sights on something else — classes and class members (properties).

Imagine you have multiple classes that need to share the same chunk of functionality or in multiple classes you need to modify certain properties the same way.

Inheritance is nice but it can only get you so far, in these cases the usefulness of decorators becomes apparent.