Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created April 8, 2023 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Amitesh/ad7d75ec0a19be8f97c1beca87ed73b0 to your computer and use it in GitHub Desktop.
Save Amitesh/ad7d75ec0a19be8f97c1beca87ed73b0 to your computer and use it in GitHub Desktop.

Decorator in JavaScript and Typescript

  • In JavaScript, we can apply decorators to class fields, methods, and the entire class. Therefore, we can’t use decorators on plain objects. They only work with classes.
  • Decorators are not a standard JavaScript feature. They are in stage 3 of the ECMA TC39 specification phase. To use JavaScript Decorators we need to set up a transpiler tool in our development environment, like Babel.
  • Decorator is concept and can be in form of function or start with @.

There are function decorator and class and it's member decorator. Fot indepenedent/global function we can decorate it by wrapping it inside another function but for class decorator we can use the @ symbol and typescript or bable library.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment