5 ms·
The main other benefit of decorators is that they work on property descriptors, and are automatically passed property names and the target object, so you have a
by loganfsmyth 11y ago
The main other benefit of decorators is that they work on property descriptors, and are automatically passed property names and the target object, so you have a bit more info.
Having the descriptor means for instance that you can switch a value to use a getter function, and that enables a bunch of interesting functionality that you couldn't otherwise do.
One example that I like is automatically binding methods to the current instance on first property access.