News for hackers. Stuff that matters.
Re:Implementing Private Fields for JavaScript by caymanjim on Sunday June 13, 2021 @02:59AM (#27490422)
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.
Re:Implementing Private Fields for JavaScript by the_other on Sunday June 13, 2021 @03:46AM (#27490651)
For 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.

Re:Implementing Private Fields for JavaScript by Madeindjs on Sunday June 13, 2021 @05:08PM (#27496512)
> `_` 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/...
Re:Implementing Private Fields for JavaScript by andy_ppp on Sunday June 13, 2021 @06:19AM (#27491342)
Why can’t they just introduce a new private keyword, i.e. private let myVar = 0;
Re:Implementing Private Fields for JavaScript by ezekg on Sunday June 13, 2021 @11:33PM (#27499000)
The proposal doesn’t even know.
Re:Implementing Private Fields for JavaScript by unwind on Sunday June 13, 2021 @05:48AM (#27491211)
As far as I know it's the standard way in Python.
Re:Implementing Private Fields for JavaScript by v413 on Sunday June 13, 2021 @03:42AM (#27490628)
The # symbol denoting private fields has already been finalized and approved to be a legal part of the language. No going back.
Re:Implementing Private Fields for JavaScript by elondaits on Sunday June 13, 2021 @07:44AM (#27491738)
Re:Implementing Private Fields for JavaScript by ssdspoimdsjvv on Sunday June 13, 2021 @05:56AM (#27491240)
One more reason to just use Typescript.
Re:Implementing Private Fields for JavaScript by andy_ppp on Sunday June 13, 2021 @06:21AM (#27491350)
Variables 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.
Re:Implementing Private Fields for JavaScript by tylerhou on Sunday June 13, 2021 @06:57AM (#27491534)
I don’t know of any way of accessing lexically bound variables that are captured by a closure if there is no explicit getter.
Re:Implementing Private Fields for JavaScript by throw_m239339 on Sunday June 13, 2021 @09:07PM (#27498219)
Typescript is a mostly superset of javascript. Typescript does/will also support # for private fields so it changes absolutely nothing.
Re:Implementing Private Fields for JavaScript by cutler on Sunday June 13, 2021 @08:17AM (#27491907)
Better would be priv.
Re:Implementing Private Fields for JavaScript by nikolay on Monday June 14, 2021 @12:27PM (#27504599)
This is exactly what I came up with, too, because it follows "constant => const" analogy. Why are constants not "$name" using the same perverted logic?!
Re:Implementing Private Fields for JavaScript by nobody0 on Sunday June 13, 2021 @03:48AM (#27490669)
Yes, _ is much better given its precenses in other languages. I would associate # with a number or a link.
Re:Implementing Private Fields for JavaScript by nikolay on Monday June 14, 2021 @12:29PM (#27504620)
The 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".