tyneq / reflect
Function: reflect()
reflect<
T>(target,options?):ReflectionContext<T>
Defined in: src/utility/reflect.ts:236
Creates a ReflectionContext for the given target.
The target can be:
- A constructor function - reflects the class prototype (instance members). Preferred form.
- A prototype object (
MyClass.prototype) - reflects it directly. - Any object - reflects the object's own properties directly.
Type Parameters
| Type Parameter |
|---|
T extends object |
Parameters
| Parameter | Type |
|---|---|
target | T | (...args) => T |
options | ReflectOptions |
Returns
Example
ts
import { reflect } from "tyneq/utility";
class Service {
public name = "svc";
public get label(): string { return this.name; }
public run(): void { /* ... */ }
}
const ctx = reflect(Service);
ctx.methods(); // -> [{ kind: "method", name: "run", ... }]
ctx.accessors(); // -> [{ kind: "accessor", name: "label", canRead: true, canWrite: false, ... }]
const m = ctx.getMethod("run");
m.invoke(new Service()); // calls run()Walk the full prototype chain:
ts
const ctx = reflect(DerivedClass, { inherited: true });
ctx.members(); // includes members from base classes too