import { makeDecorator } from "https://deno.land/x/enzastdlib@v0.0.4/decorators/mod.ts";
Returns a Decorator
instance that provides for handling scoped metadata
on functions.
Examples
Example 1
Example 1
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import { makeDecorator } from 'https://deno.land/x/enzastdlib/decorators/mod.ts';
type MyDecoratorValue = number;
const mydecorator = makeValidator<MyDecoratorValue>((func, value) => {
// Our `Decorator` object provides simplified access to scoped metadata. So
// we can use it to assign the initialization metadata to the function.
mydecorator.set(func, value);
});
// We are initializing the decorator onto our desired function with some metadata.
mydecorator(my_func, 42);
function my_func() {
console.log('Hello World!');
}
assertEquals(
mydecorator.has(my_func),
true,
);
assertEquals(
mydecorator.get(my_func),
42,
);