Chapter 3. Working with Encapsulation and Information Hiding

In this chapter, we will explore the relationship between encapsulation and information hiding, and we will see the different approaches to implement the visibility and accessibility of members of a JavaScript object. The following topics will be addressed in this chapter:

  • Public and private properties
  • Scope and closure
  • Techniques to protect private members
  • Getters, setters, and property descriptors
  • Property definition in ES6 classes

Encapsulation and information hiding

Encapsulation is one of the basic principles of the OOP paradigm. It allows us to bundle it into one object both data and functionalities that operate on that data.

Using the methods exposed by the object to manipulate the data, ...

Get Mastering JavaScript Object-Oriented Programming 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.