Private brand checks a.k.a. `#foo in obj`
v8.dev
v8.dev
> Since private names are only available inside the class which defines them, the test must also occur inside the class
So code in other classes can't introduce dependance on this atleast. It's not any pickier than checking the class of an object, but only within the class itself. It's a narrower footgun that I'd first considered it to be.
In all seriousness, this looks like a massive footgun and feels to me like something you wouldn't want to use in what's essentially a duck-typed language. Or is there something this Ruby lover is missing?
The general takeaway is private fields are private, and the "in" operator is consistent with that.
If constructor code results in an incorrectly constructed object, that's simply a bug in the constructor code, not really anything specifically to do with fields, private fields, in operator, etc. (I guess this is a criticism of the post. Bringing this up implies it's somehow relevant to the topic, but it isn't and causes confusion.)
Also note the bulk of the article is about edge cases that are unlikely to occur in practice. It helped me understand what they were talking about when I realized this. You aren’t actually going to inherit a private field through the prototype chain or deal with partially-initialized objects, in all likelihood.
Personally, as a TypeScript fan, my class-oriented code uses the “protected” keyword a lot, and it suits my purposes well. I don’t need runtime “safety,” and I find that truly private fields to one class (not subclasses or tests, for example) have limited use.