O'Reilly logo

Pro JavaScript™ Design Patterns by Dustin Diaz, Ross Harmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required