0
# Class System Helpers
1
2
Runtime support for modern class syntax including construction, inheritance, private fields, and decorators. These helpers enable ES6+ class features to work in older JavaScript environments.
3
4
## Capabilities
5
6
### Class Construction
7
8
#### _class_call_check
9
10
Ensures a class constructor is called with the `new` operator.
11
12
```javascript { .api }
13
/**
14
* Ensures a class constructor is called with the new operator
15
* @param {any} instance - The instance being created
16
* @param {Function} Constructor - The constructor function
17
* @throws {TypeError} If class called without new
18
*/
19
function _class_call_check(instance, Constructor): void;
20
```
21
22
**Usage Example:**
23
24
```javascript
25
function MyClass() {
26
_class_call_check(this, MyClass);
27
// Constructor logic here
28
}
29
```
30
31
#### _create_class
32
33
Defines properties on class prototype and constructor (static properties).
34
35
```javascript { .api }
36
/**
37
* Defines properties on class prototype and constructor
38
* @param {Function} Constructor - The constructor function
39
* @param {Array} protoProps - Array of property descriptors for prototype
40
* @param {Array} staticProps - Array of property descriptors for constructor
41
* @returns {Function} The constructor with defined properties
42
*/
43
function _create_class(Constructor, protoProps, staticProps): Function;
44
```
45
46
**Usage Example:**
47
48
```javascript
49
function MyClass() {
50
_class_call_check(this, MyClass);
51
}
52
53
_create_class(MyClass, [
54
{
55
key: "instanceMethod",
56
value: function instanceMethod() {
57
return "instance";
58
}
59
}
60
], [
61
{
62
key: "staticMethod",
63
value: function staticMethod() {
64
return "static";
65
}
66
}
67
]);
68
```
69
70
### Class Inheritance
71
72
#### _inherits
73
74
Sets up prototype-based inheritance between classes.
75
76
```javascript { .api }
77
/**
78
* Sets up prototype-based inheritance between classes
79
* @param {Function} subClass - The child class constructor
80
* @param {Function|null} superClass - The parent class constructor or null
81
*/
82
function _inherits(subClass, superClass): void;
83
```
84
85
#### _inherits_loose
86
87
Loose mode inheritance setup (simpler, less spec-compliant).
88
89
```javascript { .api }
90
/**
91
* Loose mode inheritance setup
92
* @param {Function} subClass - The child class constructor
93
* @param {Function} superClass - The parent class constructor
94
*/
95
function _inherits_loose(subClass, superClass): void;
96
```
97
98
#### _create_super
99
100
Creates a super constructor function for derived classes.
101
102
```javascript { .api }
103
/**
104
* Creates a super constructor function for derived classes
105
* @param {Function} Derived - The derived class constructor
106
* @returns {Function} Super constructor function
107
*/
108
function _create_super(Derived): Function;
109
```
110
111
#### _call_super
112
113
Calls super constructor with proper context handling.
114
115
```javascript { .api }
116
/**
117
* Calls super constructor with proper context
118
* @param {any} _this - The current instance
119
* @param {Function} derived - The derived class
120
* @param {Array} args - Arguments to pass to super
121
* @returns {any} Result of super constructor call
122
*/
123
function _call_super(_this, derived, args): any;
124
```
125
126
#### _possible_constructor_return
127
128
Handles possible constructor return values in inheritance.
129
130
```javascript { .api }
131
/**
132
* Handles possible constructor return values in inheritance
133
* @param {any} self - The current instance
134
* @param {any} call - Result of super constructor call
135
* @returns {any} The appropriate instance
136
*/
137
function _possible_constructor_return(self, call): any;
138
```
139
140
### Constructor Utilities
141
142
#### _construct
143
144
Constructs objects with dynamic arguments using Reflect.construct.
145
146
```javascript { .api }
147
/**
148
* Constructs objects with dynamic arguments
149
* @param {Function} Parent - Constructor function
150
* @param {Array} args - Arguments array
151
* @param {Function} Class - Target class for construction
152
* @returns {any} Constructed instance
153
*/
154
function _construct(Parent, args, Class): any;
155
```
156
157
#### _wrap_native_super
158
159
Wraps native constructors for proper inheritance.
160
161
```javascript { .api }
162
/**
163
* Wraps native constructors for proper inheritance
164
* @param {Function} Class - The class to wrap
165
* @returns {Function} Wrapped constructor
166
*/
167
function _wrap_native_super(Class): Function;
168
```
169
170
#### _is_native_function
171
172
Checks if a function is a native function.
173
174
```javascript { .api }
175
/**
176
* Checks if a function is a native function
177
* @param {Function} fn - Function to check
178
* @returns {boolean} True if native function
179
*/
180
function _is_native_function(fn): boolean;
181
```
182
183
#### _is_native_reflect_construct
184
185
Checks if Reflect.construct is available and native.
186
187
```javascript { .api }
188
/**
189
* Checks if Reflect.construct is available and native
190
* @returns {boolean} True if Reflect.construct is native
191
*/
192
function _is_native_reflect_construct(): boolean;
193
```
194
195
### Class Error Handling
196
197
#### _class_name_tdz_error
198
199
Throws an error for class name temporal dead zone violations.
200
201
```javascript { .api }
202
/**
203
* Throws an error for class name TDZ violations
204
* @param {string} name - The class name
205
* @throws {ReferenceError} Class name TDZ error
206
*/
207
function _class_name_tdz_error(name): never;
208
```
209
210
#### _assert_this_initialized
211
212
Ensures `this` is initialized in constructors.
213
214
```javascript { .api }
215
/**
216
* Ensures this is initialized in constructors
217
* @param {any} self - The this value to check
218
* @returns {any} The initialized this value
219
* @throws {ReferenceError} If this is not initialized
220
*/
221
function _assert_this_initialized(self): any;
222
```
223
224
### Property Access Helpers
225
226
#### _get
227
228
Gets property values with prototype chain traversal.
229
230
```javascript { .api }
231
/**
232
* Gets property values with prototype chain traversal
233
* @param {Object} target - Target object
234
* @param {string|symbol} property - Property key
235
* @param {Object} receiver - Receiver object
236
* @returns {any} Property value
237
*/
238
function _get(target, property, receiver): any;
239
```
240
241
#### _set
242
243
Sets property values with proper prototype handling.
244
245
```javascript { .api }
246
/**
247
* Sets property values with proper prototype handling
248
* @param {Object} target - Target object
249
* @param {string|symbol} property - Property key
250
* @param {any} value - Value to set
251
* @param {Object} receiver - Receiver object
252
* @param {boolean} isStrict - Strict mode flag
253
* @returns {boolean} Success flag
254
*/
255
function _set(target, property, value, receiver, isStrict): boolean;
256
```
257
258
#### _super_prop_base
259
260
Gets the base object for super property access.
261
262
```javascript { .api }
263
/**
264
* Gets the base object for super property access
265
* @param {Object} object - Current object
266
* @param {string|symbol} property - Property key
267
* @returns {Object} Base object for super access
268
*/
269
function _super_prop_base(object, property): Object;
270
```
271
272
#### _update
273
274
Handles update operations on properties.
275
276
```javascript { .api }
277
/**
278
* Handles update operations on properties
279
* @param {Object} target - Target object
280
* @param {string|symbol} property - Property key
281
* @param {Function} updater - Update function
282
* @param {Object} receiver - Receiver object
283
* @returns {any} Updated value
284
*/
285
function _update(target, property, updater, receiver): any;
286
```