typescript - static constructor
TypeScript[Edit]
+
0
-
0
TypeScript - static constructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18// ... class SomeClass { // ... private static _field: unknown; // ... static { // static constructor // ... this._field = 'Some value here ...'; // ... } // ... } // ... // Hint: to access class fields from static constructor use `static` keyword with fields and `this` inside static constructor.
[Edit]
+
0
-
0
TypeScript - static constructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15class SomeClass { // ... static { // static constructor // ... } // ... } // Hint: to access class fields from static constructor use `static` keyword with fields and `this` inside static constructor. // See also: // // 1. https://dirask.com/snippets/TypeScript-static-constructor-D6d6Rj
[Edit]
+
0
-
0
TypeScript - static constructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21// Note: the solution has trick that that lets to create static constructor. const STATIC_CONSTRUCTOR = Symbol(); class SomeClass { // ... private static _field: unknown; // ... public static[STATIC_CONSTRUCTOR] = (): void => { // static constructor definition // ... this._field = 'Some value here ...'; // ... } // ... } SomeClass[STATIC_CONSTRUCTOR](); // static constructor calling // Hint: to access class fields from static constructor use `static` keyword with fields and `this` inside static constructor.
[Edit]
+
0
-
0
typescript - static constructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22// Note: the solution has trick that that lets to create static constructor. const STATIC_CONSTRUCTOR = Symbol(); class SomeClass { // ... public static[STATIC_CONSTRUCTOR] = (): void => { // static constructor definition // ... } // ... } SomeClass[STATIC_CONSTRUCTOR](); // static constructor calling // Hint: to access class fields from static constructor use `static` keyword with fields and `this` inside static constructor. // See also: // // 1. https://dirask.com/snippets/TypeScript-static-constructor-DLaQRp