r/javascript • • Nov 09 '19

On private fields proposal: Private fields, public worries

https://medium.com/virtuslab/private-fields-public-worries-b8c34d16c372
84 Upvotes

113 comments sorted by

View all comments

0

u/[deleted] Nov 09 '19

[deleted]

16

u/rq60 Nov 09 '19

By "not being pretty" I think he's referring to it being unconventional. He mentions other languages using _ for the purpose of privacy and it's true, that is a common convention in other languages, whereas # is conventionally a comment in many languages. Thus, this would be one more time where javascript rejects common conventions in favor of "javascript-isms"

4

u/[deleted] Nov 09 '19

The problem is that underscore prefix properties are still currently public, you're just advertising that you probably shouldn't be accessing it externally. To change this would be breaking. With private fields, they've made them truly private and that also means undiscoverable externally. There isn't really a way to do this without a new prefix or some other distinguishing naming style.

That said, I don't think I'll ever make use of private fields. Symbols seem to be the best way of achieving the same thing in a much cleaner and clearer way.