CHAPTER 3Encapsulation and Information Hiding

Creating objects with private members is one of the most basic and useful features of any object-oriented language. Declaring a method or attribute as private allows you to shield your implementation details from other objects and promotes a loose coupling between them. It allows you to maintain the integrity of your data and impose constraints on how it can be modified. It also makes your code more reliable and easier to debug in environments where many people are working on the same code base. In short, encapsulation is a cornerstone of object-oriented design.

Despite the fact that JavaScript is an object-oriented language, it does not have any built-in mechanisms for declaring members to be public ...

Get Pro JavaScript™ Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.