🔸private member
JS ⟩ value ⟩ object ⟩ class ⟩ member ⟩ private
private members are not inherited❗
class A {
// ⭐️ private members // # means "private"
#a; // this.#a = undefined
#b = 0; // this.#b = 0
get #c() { return 0 } // this.#c (private getter)
#d() { ... } // this.#d() (private method)
// ⭐️ private static members
// (accessable only within the class body)
static #staticProp; // A.#staticProp
static get #CONST() { return 0 } // A.#CONST
static #staticMethod() { ... } // A.#staticMethod()
}
never use "this" to access a private static field,
always use the direct class name.
👉 📗 2ality.com ⟩ ECMAScript proposal: private class fields
supporting environments
Last updated
Was this helpful?