5 ms·
Hopefully they come up with something better than a # prefix for identifying private fields. It seems like a small thing, but it looks clunky and arbitrary. Eve
by caymanjim 5y ago
Hopefully they come up with something better than a # prefix for identifying private fields. It seems like a small thing, but it looks clunky and arbitrary. Even _ would be better, but best of all would be adding a keyword or something instead of using a glyph.
- v413 5y agoThe # symbol denoting private fields has already been finalized and approved to be a legal part of the language. No going back.
- the_other 5y agoFor some time, there was a trend of adding _ to property and method names to indicate “I’m pretending to be private, don’t use me” (I think this happens in several languages, but I only know JS well). I suspect there’s a risk that if the committee standardised on _ rather than #, it would actually break a load of older apps and content. There’s a good chance the _convention was abused in those earlier codebases.
- unwind 5y agoAs far as I know it's the standard way in Python.
- andy_ppp 5y agoWhy can’t they just introduce a new private keyword, i.e. private let myVar = 0;
- ezekg 5y agoThe proposal doesn’t even know.
- Madeindjs 5y ago> `_` would cause compatibility issues with existing JavaScript code, which has allowed `_` at the start of an identifier or (public) property name for a long time. -- https://github.com/tc39/proposal-private-fields/blob/master/FAQ.md https://github.com/tc39/proposal-private-fields/blob/master/...
- nobody0 5y agoYes, _ is much better given its precenses in other languages. I would associate # with a number or a link.
- nikolay 5y agoThe semantic meaning of "#name" is not private. In fact, the "_" is much more meaningful than "#", which is always used as in the meaning of "number" or "index".
- ssdspoimdsjvv 5y agoOne more reason to just use Typescript.
- andy_ppp 5y agoVariables are never truly private in the compiled JS though. You can fake it using clever closure techniques but there are still ways to access the vars as I understand it. This is fixing that at the JS level.
- tylerhou 5y agoI don’t know of any way of accessing lexically bound variables that are captured by a closure if there is no explicit getter.
- throw_m239339 5y agoTypescript is a mostly superset of javascript. Typescript does/will also support # for private fields so it changes absolutely nothing.
- elondaits 5y agoThis is all covered here: https://github.com/tc39/proposal-private-fields/blob/master/FAQ.md https://github.com/tc39/proposal-private-fields/blob/master/...
- cutler 5y agoBetter would be priv.
- nikolay 5y agoThis is exactly what I came up with, too, because it follows "constant => const" analogy. Why are constants not "$name" using the same perverted logic?!