There are 2 ways to achieve Encapsulation in JS:
- Protected Properties and Methods: coding convention (not true private), use
_
before a property to notify other developer this property is protected and should not be used directly. - Private Class Fields and Methods: languague feature that is still under proposal, might not work for every browser and are subjected to syntax change.
// 1) Public fields
// 2) Private fields