You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
So private fields has a little quirk compared to public fields, and I'm trying to understand why the restriction exists.
The quirk:
class N extends class { constructor(o) { return o; } }
{
a = 1;
};
var obj = {};
new N(obj);
new N(obj);
This is fine, with a public field. But if you change that to a private field, by going a => #a, then the second constructor call is supposed to issue a type error: PrivateFieldAdd, step 4.
What I don't really understand is why this change in semantics relative to public fields? It feels weird to have these two parallel constructs that don't behave the same in parallel situations.
(There's also an albeit very small argument that this also makes refactoring public fields into private fields more of a footgun, as code which would work on public fields breaks when translated into a private field for reasons outside of visibility)