class ClassWithPrivate {
#privateField;
#privateFieldWithInitializer = 42;
#privateMethod() {
/ …
}
static #privateStaticField;
static #privateStaticFieldWithInitializer = 42;
static #privateStaticMethod() {
/ …
}
}
There are some additional syntax restrictions:
- All private identifiers declared within a class must be unique. The namespace is shared between static and instance elements. The only exception is when the two declarations define a getter-setter pair.
- The private identifier cannot be
#constructor
.