You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.error('Failed to create instance:', error);
97
96
}
97
+
```
98
+
```
99
+
100
+
#### API Overview
101
+
The ReflectionClass<T> takes a target T (which can be a class constructor or an object instance) in its constructor.
102
+
103
+
Core Methods
104
+
constructor(target: T): Initializes the reflection for the given target.
105
+
106
+
- getName(): string: Gets the name of the class.
107
+
108
+
- getConstructor(): Function: Gets the constructor function.
109
+
110
+
- getPrototype(): object | null: Gets the prototype object of the class.
111
+
112
+
- getParentClass(): Function | null: Gets the parent class constructor.
113
+
114
+
- getParentClassName(): string | null: Gets the name of the parent class.
115
+
116
+
- isClass(): boolean: Checks if the reflected target is a class constructor.
117
+
118
+
- isInstance(): boolean: Checks if the reflected target is an object instance.
119
+
120
+
Property Introspection
121
+
- getOwnProperties(): string[]: Gets an array of own property names (static for classes, instance-specific for objects).
122
+
123
+
- getProperties(): string[]: Gets an array of all property names, including inherited ones (static for classes, instance and prototype chain for objects).
124
+
125
+
- hasOwnProperty(name: string): boolean: Checks if the target has a specific own property.
126
+
127
+
- hasProperty(name: string): boolean: Checks if the target has a specific property (including the prototype chain).
128
+
129
+
Method Introspection
130
+
- getOwnMethods(): string[]:
131
+
132
+
For classes: Gets own static methods.
133
+
134
+
For instances: Gets methods from the instance's direct prototype.
135
+
136
+
- `getMethods()`: string[]:
137
+
138
+
For classes: Gets all static methods (own and inherited).
139
+
140
+
For instances: Gets all methods (own instance methods, prototype methods, and inherited methods).
141
+
142
+
- hasOwnMethod(name: string): boolean:
143
+
144
+
For classes: Checks for an own static method.
145
+
146
+
For instances: Checks for a method on the instance's direct prototype.
147
+
148
+
- hasMethod(name: string): boolean: Checks if the target or its prototype chain has a method with the given name (includes instance-specific methods).
149
+
150
+
Instantiation and Type Checking
151
+
- isInstantiable(): boolean: Checks if the reflected target (typically a class) can be instantiated.
152
+
153
+
- newInstance(...args: any[]): object | null: Creates a new instance of the reflected class. Throws a TypeError if the target is not a constructor.
154
+
155
+
- isInstanceCheck(obj: any): boolean: Checks if a given object obj is an instance of the reflected class (meaningful only when reflecting a class constructor).
156
+
157
+
Utility
158
+
- toString(): string: Returns a string representation of the reflected entity.
0 commit comments