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:

Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 â‹… 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 â‹… 10 min read
Integrating Django Templates With React For Dynamic Webpages

Integrating Django templates with React for dynamic webpages

Create a dynamic demo blog site using Django and React to demonstrate Django’s server-side functionalities and React’s interactive UI.

Kayode Adeniyi
Apr 18, 2024 â‹… 7 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