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:

A guide to image overlays in CSS

Learn the basics of applying image overlays in CSS and explore more interactive techniques like hover effects and animations.

Ibadehin Mojeed
Mar 11, 2025 â‹… 5 min read

How to use EJS to template your Node.js application

EJS makes working with templates in Node.js super easy — but only if you know how to use it. This guide walks you through the essentials and more.

Samuel Olusola
Mar 11, 2025 â‹… 15 min read
Remote Branches In Git LogRocket

How to check out a remote branch in Git: A step-by-step guide

Learn how to list, fetch, and checkout remote Git branches, plus troubleshoot outdated branch lists effectively.

Oyinkansola Awosan
Mar 11, 2025 â‹… 8 min read
How To Switch Node.js Versions With NVM

How to switch Node.js version: A cross-platform guide for NVM and alternatives

Use NVM, Node Version Manager, to switch between Node.js versions, simplifying your development process.

Precious Luke
Mar 10, 2025 â‹… 9 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