I was wondering if anyone could explain this example from the MDN docs:
let getDPrivateField;
class D {
#privateField;
constructor(v) {
this.#privateField = v;
}
static {
getDPrivateField = (d) => d.#privateField;
}
}
getDPrivateField(new D('private'));
//private
I understand that each static block is defined on the class and executed when the class constructor declaration is evaluated. What I don't understand is how main has access to the getDPrivateField arrow function outside of its definition within the constructor. Doesn't class create its own scope and variables declared within are local variables? Shouldn't there be two versions of getDPrivateField and the one outside of the D class constructor is undefined?