Decorator
A decorator is a programming-language construct that adds metadata or behavior to, or transforms, a program declaration, often a function or class.
Essential TypeScript 5, Third Edition
A decorator function is a function invoked when a decorator is applied and returns the replacement class feature.
- How it is used
- Transforms class features without editing their implementations and describes application building blocks in Angular.
- How deep it goes
- Works through method replacements, context data, generic constraints, class type limitations, factories, stacking order, and shared state.
- Examples
- Uses a timed method, a serializing subclass, stacked message decorators, accumulated timing data, and Angular module and component declarations.
- What you can do after
- Build it from scratch to wrap methods, configure each application, and recognize a class decorator’s TypeScript type limitation.
Read how Essential TypeScript 5, Third Edition explains decorator →
Python How-To
A decorator is a callable that modifies or extends the behavior of another callable or class without changing its underlying definition.
- How it is used
- Uses decorators to share timing and logging behavior across functions and to generate data-class boilerplate.
- How deep it goes
- Explains wrappers, argument and return forwarding, metadata, and callable classes, while deferring a full account of closures.
- Examples
- Demonstrates timing functions and preserving metadata, then challenges readers to compare CSV and SQLite operations with a timing decorator.
- What you can do after
- Build it from scratch as a timing wrapper that forwards arguments and results and preserves metadata with functools.wraps.
The Well-Grounded Python Developer: How the pros use Python and Flask
A Python decorator is a callable construct that extends or modifies a function or method without changing its source definition.
- How it is used
- Uses decorators to preserve direct attribute access while adding coordinate checks, and to add timing around a function call.
- How deep it goes
- Works through property getters and setters plus a hand-written timing wrapper, without developing an exhaustive account of decorator behavior.
- Examples
- Shows a rectangle coordinate property and a timing decorator applied to a delayed task.
- What you can do after
- Apply it via Python’s `@property` and setter decorators to manage coordinates, or write a wrapper to time a function.
Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains decorator →
Django in Action
A decorator is a Python language construct that associates additional behavior or metadata with a function or class.
- How it is used
- Turns Django view functions into API endpoints while attaching HTTP methods and endpoint configuration.
- How deep it goes
- Explains decorator syntax, route configuration, request flow, and registration, but does not descend into decorator implementation internals.
- Examples
- Uses a RiffMates hello endpoint and shows Router-to-NinjaAPI-to-Django URL registration.
- What you can do after
- Apply it via Django Ninja to build routed API endpoints with method, schema, naming, and authentication configuration.
The Joy of JavaScript
A wrapper-like construct that augments method behavior without changing the method's core implementation.
- How it is used
- Separates cross-cutting behavior from business logic through dynamically intercepted method calls.
- How deep it goes
- Explains object specifications, before-and-after actions, higher-order wrappers, and Proxy/Reflect wiring, but not decorator syntax.
- Examples
- Demonstrates Counter validation, credential tracing, password obfuscation, and composition of nested proxies.
- What you can do after
- Apply validation, tracing, logging, or return-value enhancement without modifying the decorated object’s business methods.
Build Python Web Apps with Streamlit
A decorator is a Python construct that modifies or extends a function or class by wrapping it with additional behavior.
- How it is used
- Applies caching and popup-dialog behavior to Streamlit functions without rewriting their core data-loading or rendering logic.
- How deep it goes
- Defines decorators through two working Streamlit examples, but does not explain decorator implementation internals.
- Examples
- Uses @st.cache_data on load_data and @st.dialog on a drilldown function displaying main and comparison dataframes.
- What you can do after
- Apply Streamlit decorators to cache data-loading results and render interactive drilldown content in modal dialogs.
Read how Build Python Web Apps with Streamlit explains decorator →
Software Engineering for Data Scientists
A decorator is a callable Python construct that wraps a function or class to extend or alter its behavior without changing its source definition.
- How it is used
- Applies reusable controls such as timeouts and profiling to data-science functions without rewriting their core code.
- How deep it goes
- Defines @ syntax and demonstrates wrapping functions, but deliberately provides only a highlighted introduction rather than decorator internals.
- Examples
- Uses stopit around random-forest training and line-profiler around an artist-filtering function.
- What you can do after
- Apply it via stopit or line-profiler to impose function timeouts or inspect line-by-line execution time.
Read how Software Engineering for Data Scientists explains decorator →
Pro Angular 16
A decorator is a language construct that attaches metadata or behavior to a class or other declaration.
- How it is used
- Identifies an Angular class as a component and configures how its generated content enters the page.
- How deep it goes
- Defines metadata properties and traces selector matching to a custom element, while deferring further runtime details.
- Examples
- Uses AppComponent with app-root, app.component.html, and app.component.css in a todo application.
- What you can do after
- Apply it via Angular to configure a component class and connect it to an HTML element.
Web Component Development with Modern Libraries and Tooling
A JavaScript language feature that applies declarative metadata or behavior to classes and class members.
- How it is used
- Uses declarative annotations to configure web components and reduce implementation boilerplate.
- How deep it goes
- Explains decorator targets, configuration options, attribute synchronization, and reactive updates, but not decorator implementation internals.
- Examples
- Demonstrates component registration, property mapping, attribute conversion, and a reactive my-math component with observable values.
- What you can do after
- Apply decorators via Stencil or FAST to declare custom elements, synchronize attributes, expose APIs, and update bindings reactively.
Read how Web Component Development with Modern Libraries and Tooling explains decorator →
Also covered in
- Geometry for Programmers
- Python Concurrency with asyncio
- Grokking Web Application Security
- Grokking Software ArchitectureIn early access (MEAP)
- Designing AI SystemsIn early access (MEAP)
- The Quick Python Book, Fourth Edition
- Build an AI Agent (From Scratch)
- Deep Learning with JAX
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- accessor methodAn accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
Related concepts
- injectable decoratorincludes · The Injectable decorator is an Angular class decorator that marks a class as eligible for dependency injection and configures its injectable metadata.
- component decoratorincludes · A component decorator or annotation attaches metadata to a class to identify or configure it as a component managed by a software framework.
- functionuses · A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- Angularused by · Angular is an open-source, TypeScript-based web application framework and platform for building structured, component-based client-side applications.
Questions about decorator
What is decorator?
A decorator is a programming-language construct that adds metadata or behavior to, or transforms, a program declaration, often a function or class.
Which Manning books explain decorator?
Essential TypeScript 5, Third Edition, Python How-To, The Well-Grounded Python Developer: How the pros use Python and Flask, Django in Action, The Joy of JavaScript, Build Python Web Apps with Streamlit, Software Engineering for Data Scientists, Pro Angular 16 and 1 more.
What should I know before learning decorator?
Manning books that teach decorator usually introduce function, Python, attribute and accessor method first.
What kinds of decorator are there?
Kinds of decorator include injectable decorator, component decorator and attr decorator.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.








