Hey all.
I am learning JS at the moment and I have learned about classes and how all their fields are public by default. I have also learned that it is not always wanted so a past workarounds included:
- adding "_" prefix to the key name for other developers to understand your intentions,
- using factory functions
Nowadays "#" is supported to be used for this.
My questions:
1. Why is it important that certain/all keys are private and not accessible? Do you have a real-life example of this?
2. Now that "#" prefix is implemented and widely supported, do people even use factory functions these days? Why (whether yes or no)?
3. If we expect some key values to change, why should we create extra functions to access those (getters, setters) instead of using the dot-notation? Why is dot-notation problematic?
Note: Please no links to MDN, I have been there, it is not understandable to me. It has been written for people who already understand it or already have some experience in the field, not for newbies like me.
Thanks.