Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/alosaur/src/injection/reflect.ts>Reflect.decorate

Alosaur - Deno web framework with many decorators
Very Popular
Go to Latest
function Reflect.decorate
import { Reflect } from "https://deno.land/x/alosaur@v0.28.0/src/injection/reflect.ts";
const { decorate } = Reflect;

Applies a set of decorators to a target object.

Examples

class Example { }

// constructor Example = Reflect.decorate(decoratorsArray, Example);

Parameters

decorators: ClassDecorator[]

An array of decorators.

target: Function

The target object.

Returns

Function

The result of applying the provided decorators.

Applies a set of decorators to a property of a target object.

Examples

class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property;

static staticMethod() { } method() { } }

// property (on constructor)
Reflect.decorate(decoratorsArray, Example, "staticProperty");

// property (on prototype)
Reflect.decorate(decoratorsArray, Example.prototype, "property");

// method (on constructor)
Object.defineProperty(Example, "staticMethod",
    Reflect.decorate(decoratorsArray, Example, "staticMethod",
        Object.getOwnPropertyDescriptor(Example, "staticMethod")));

// method (on prototype)
Object.defineProperty(Example.prototype, "method",
    Reflect.decorate(decoratorsArray, Example.prototype, "method",
        Object.getOwnPropertyDescriptor(Example.prototype, "method")));

Parameters

decorators: (PropertyDecorator | MethodDecorator)[]

An array of decorators.

target: any

The target object.

propertyKey: string | symbol

The property key to decorate.

optional
attributes: PropertyDescriptor | null

A property descriptor.

Returns

PropertyDescriptor | undefined

Applies a set of decorators to a property of a target object.

Examples

class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property;

static staticMethod() { } method() { } }

// property (on constructor)
Reflect.decorate(decoratorsArray, Example, "staticProperty");

// property (on prototype)
Reflect.decorate(decoratorsArray, Example.prototype, "property");

// method (on constructor)
Object.defineProperty(Example, "staticMethod",
    Reflect.decorate(decoratorsArray, Example, "staticMethod",
        Object.getOwnPropertyDescriptor(Example, "staticMethod")));

// method (on prototype)
Object.defineProperty(Example.prototype, "method",
    Reflect.decorate(decoratorsArray, Example.prototype, "method",
        Object.getOwnPropertyDescriptor(Example.prototype, "method")));

Parameters

decorators: (PropertyDecorator | MethodDecorator)[]

An array of decorators.

target: any

The target object.

propertyKey: string | symbol

The property key to decorate.

attributes: PropertyDescriptor

A property descriptor.

Returns

PropertyDescriptor