Skip to main content
A static private getter in JavaScript is a class-level accessor method prefixed with a hash (#) that dynamically computes and returns a value. It is bound to the class constructor itself rather than its instances, and its invocation is strictly encapsulated within the lexical scope of the class body. Because it is a getter, it is accessed as a property lookup rather than a function call. Because it is static, its internal this context refers to the class constructor. Because it is private, the JavaScript engine enforces hard privacy, throwing a SyntaxError if access is attempted from outside the class definition.

Technical Characteristics

  • Lexical Scoping: The # identifier is resolved lexically. The getter can only be referenced by code physically located within the class {} block.
  • Storage and Binding: According to the ECMAScript specification, a static private getter is stored in the [[PrivateElements]] internal slot of the class constructor function object. This contrasts with private instance getters, which are installed in the [[PrivateElements]] internal slot of individual instances, and public instance getters, which are defined on the class prototype.
  • Context (this): When invoked, the this keyword inside the static private getter evaluates to the class constructor itself, allowing access to other static private or public members.
  • Non-writable: A getter without a corresponding setter creates a read-only property. Attempting to assign a value to a static private getter throws a TypeError.

Syntax and Invocation Mechanics

To invoke a static private getter, you must reference it via the class name (or this if within another static method) from inside the class body.

Memory and Reflection

Static private getters are not observable via standard JavaScript reflection mechanisms.
  • They do not appear in Object.getOwnPropertyNames(ClassName).
  • They do not appear in Object.getOwnPropertySymbols(ClassName).
  • They cannot be accessed dynamically using bracket notation (e.g., ClassName['#nodePrefix'] evaluates to undefined looking for a public string key, rather than accessing the private getter).
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More