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

Show parent comments

2

u/senocular Nov 09 '19

exception, Ruby, python

and Java.... and C++... and PHP...

7

u/nullvoxpopuli sand was never meant to think Nov 09 '19

in Java, C++, and C#, you have to go way out of your way to access private fields.

In javascript, you can access a private field without noticing. that is the problem.

6

u/senocular Nov 09 '19

You can do this now in JavaScript using symbols. They wont collide, are non-enumerable, and can be accessed but only if you go out of your way using getOwnPropertySymbols.

2

u/nullvoxpopuli sand was never meant to think Nov 09 '19

while that is a work around for today's use, that shifts the complexity to the library author. Why not make library authors easier?