O'Reilly logo

Mastering JavaScript Object-Oriented Programming by Andrea Chiarelli

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

Property descriptors

Once we have found a satisfactory solution to control the visibility of an object's members, we have to face how public members can be accessed and which constraints we can set.

Controlling access to public properties

When we define public properties, we do not put any constraints on their accessibility. Consider the literal person definition:

var person = { name: "John", surname: "Smith"}; 

Public properties are readable and writable and they can be set to any value. The following assignments are perfectly legal:

var personName = person.name; 
 
person.name = "Mario"; 
person.surname = [1, 2, 3]; 

But for the meaning we want to give to the object, these assignments might not make sense or not be desirable. Assigning an array to a person's ...

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