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

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

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

Define a unique metadata entry on the target.

Examples

class Example { }

// constructor Reflect.defineMetadata("custom:annotation", options, Example);

// decorator factory as metadata-producing annotation.
function MyAnnotation(options): ClassDecorator {
    return target => Reflect.defineMetadata("custom:annotation", options, target);
}

Parameters

metadataKey: any

A key used to store and retrieve metadata.

metadataValue: any

A value that contains attached metadata.

target: any

The target object on which to define metadata.

Define a unique metadata entry on the target.

Examples

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

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

// property (on constructor)
Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty");

// property (on prototype)
Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property");

// method (on constructor)
Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod");

// method (on prototype)
Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method");

// decorator factory as metadata-producing annotation.
function MyAnnotation(options): PropertyDecorator {
    return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key);
}

Parameters

metadataKey: any

A key used to store and retrieve metadata.

metadataValue: any

A value that contains attached metadata.

target: any

The target object on which to define metadata.

propertyKey: string | symbol

The property key for the target.