DEV Community

Discussion on: Hiding details in JavaScript classes with symbols

Collapse
 
olivermensahdev profile image
Oliver Mensah • Edited

The whole idea here is to hide the details in a class so they cannot be changed outside class. It is obvious that using the approach I propose, they cannot be changed outside the class, however,@joelnet , outlined means that they can be accessed outside the class and then modified, which refutes the article.

Collapse
 
olivermensahdev profile image
Oliver Mensah

Thanks for the feedback too.

Collapse
 
galvao profile image
Er Galvão Abbott

I'm sorry this will seem like nitpicking, but I believe concepts are truly important: every property, unless static (which I don't believe JS has, but I might be wrong), is always being accessed "outside the class", since they are being accessed in an object, and not the class itself.

My goal is not the final result you wish (protecting the properties), but just to set OO straight.

Sammy Israwi is absolutely correct: the way to do it in OO is through what we call visibility (setting a property or method as public, protected or private), which seems to be in ES' future.

Thread Thread
 
olivermensahdev profile image
Oliver Mensah

No worries. I appreciate the way, we are tackling the flaws though. That is a good way of critiquing an article.