O'Reilly logo

Rediscovering JavaScript by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Decorators

The Proxy class you saw so far in this chapter is very useful to synthesize or cook up your own dynamic methods and properties into existing classes. However, sometimes you want to bring a recipe of methods that someone else has created into your own classes and functions. In other words, you want to alter your classes or functions with metadata that, for example, a library or framework expects to find. This is where decorators come in.

JavaScript decorators serve a similar purpose as annotations in Java and attributes in C#—they offer a way to extend the capabilities of the subject that they decorate or annotate.

Let’s take a quick look at an example function declaration from Async and Await.

 const​ callCompute = ​async ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required