Skip to content
Advertisement

decorating decorators: try to get my head around understanding it

I’m trying to understand how to decorate decorators, and wanted to try out the following:

Let’s say I have two decorators and apply them to the function hello():

JavaScript

Then I have to start adding other decorators for other functions, but in general the @wrap decorator will “wrap all of them”

JavaScript

How do I write a decorator, which decorates my @lower and @upper decorators? See below:

JavaScript

To achieve the same result as above by only doing:

JavaScript

Advertisement

Answer

Here’s a generic (and slightly convoluted) solution for decorating decorators with decorators (Yay!).

JavaScript
Advertisement