2021-07-21
1611
#vanilla javascript
Lawrence Eagles
58810
Jul 21, 2021 â‹… 5 min read

Understanding JavaScript decorators

Lawrence Eagles Senior full-stack developer, writer, and instructor.

Recent posts:

Nx Adoption Guide: Overview, Examples, And Alternatives

Nx adoption guide: Overview, examples, and alternatives

Let’s explore Nx features, use cases, alternatives, and more to help you assess whether it’s the right tool for your needs.

Andrew Evans
Mar 28, 2024 â‹… 9 min read
Understanding Security In React Native Applications

Understanding security in React Native applications

Explore the various security threats facing React Native mobile applications and how to mitigate them.

Wisdom Ekpotu
Mar 27, 2024 â‹… 10 min read
Warp Adoption Guide: Overview, Examples, And Alternatives

warp adoption guide: Overview, examples, and alternatives

The warp web framework for Rust offers many enticing features. Let’s see when and why you should consider using warp in your projects.

Ukeje Goodness
Mar 26, 2024 â‹… 8 min read
Integrating Next Js And Signalr For Enhanced Real Time Web App Capabilities

Integrating Next.js and SignalR to build real-time web apps

In this tutorial, you’ll learn how to integrate Next.js and SignalR to build an enhanced real-time web application.

Clara Ekekenta
Mar 25, 2024 â‹… 8 min read
View all posts

5 Replies to "Understanding JavaScript decorators"

  1. Error in code there
    “Let’s learn about this by rewriting our log decorator:

    function log(target, name, descriptor) {
    if (typeof original === ‘function’) { <—– what is "original" ?

  2. The @log class method example is completely wrong and needs to be updated. The log function receives 3 arguments: the target object, the name of the target class member and a descriptor, an object containing the implementation of the class member.

    1. Hello A, it is important to note that the decorator API has evolved. You seem to refer to the stage 2 API. Below is the updated shape of the current sage 3 API in TypeScript:

      type Decorator = (value: Input, context: {
      kind: string;
      name: string | symbol;
      access: {
      get?(): unknown;
      set?(value: unknown): void;
      };
      private?: boolean;
      static?: boolean;
      addInitializer?(initializer: () => void): void;
      }) => Output | void;

      Checkout https://github.com/tc39/proposal-decorators for more.

Leave a Reply