DEV Community

Discussion on: Hiding details in JavaScript classes with symbols

Collapse
 
sammyisa profile image
Sammy Israwi

Fantastic! I didn't know about Symbols before.

But why not use Private Fields? (which has been merged into the Class Fields proposal).

It's not yet implemented, but it is on Stage 3 so hopefully, it will be coming soon!

Collapse
 
olivermensahdev profile image
Oliver Mensah • Edited

Most often _ is prefixed before the properties to signify private properties but they can still be modified outside the class.

Thanks for the feedback and I will look into Private Fields

Collapse
 
galvao profile image
Er Galvão Abbott

That's because prefixing something with an underscore is a convention and not a language feature. In order to truly protect object properties you need visibility, as pointed by Sammy and explained in my latest reply to my own comment.

If the language doesn't have visibility features any method you use to try and protect the properties will simply be an ugly jerry-rig (that includes the prefix).