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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.