๐ฐinit static property
๐ง under construction ->
class A {
static a; // A.a = undefined
static b = 0; // A.b (static property: initialized)
static get c() { ... } // A.c (static getter)
static d() { ... } // A.d() (static method)
}class A {
// โญ๏ธ "#" means "private"
static #e; // A.#e (private static property: uninitialized)
static get #f() { ... } // A.#f (private static getter)
static #g() { ... } // A.#g() (private static method)
}ๅฆไฝๅๅงๅ้ๆ
ๅฑฌๆง
ๆนๆณ
ๆจ่ฆ
ๅช้ป
็ผบ้ป
class ClassA {
// ClassA.CONSTANT
// ๆนๆณไธ๏ผไฝฟ็จ static getter๏ผๅณๅ ClassA._CONSTANT ็ๅผ๏ผ
// โข ๅช้ป๏ผ
// โ
ๅปถ้ฒๅๅงๅ
// โข ็ผบ้ป๏ผ
// โ ้กๅค็็งๆ้ๆ
ๅฑฌๆง (ClassA._CONSTANT)
// โญ๏ธ ๆณจๆ๏ผไธ่ฝ็็ฅ `get`๏ผไธ็ถๆ่ฎๆ static methodโ
static get CONSTANT() {
// ๅฆๆ้ๆฒๅๅงๅ
// โญ๏ธ in static method/block/getter, this == class itself.
if (!this._CONSTANT) {
// ๅท่กๅๅงๅ ...๏ผ็ถๅพๅฐ็ตๆๅญๅจ็งๆ้ๆ
ๅฑฌๆงไธญ
this._CONSTANT = 100;
}
return this._CONSTANT;
}
}Last updated