Properties are members of an object. Each named property is a pair of (name, descriptor). The name is a string that allows access (using the dot notation object.propertyName or the square brackets notation object['propertyName']). The descriptor is a record of fields defining the bevahiour of the property when it is accessed (what happens to the property and what is the value returned from accessing it). By and large, a property associates a name to a behaviour (we can think of the behaviour as a black box).
There are two types of named properties:
Demonstration:
obj.propertyName1 = 5; //translates behind the scenes into
//either assigning 5 to the value field* if it is a data property
//or calling the set function with the parameter 5 if accessor property
// *actually whether an assignment would take place in the case of a data property
// also depends on the presence and value of the writable field - on that later on
The property’s type is determined by its descriptor’s fields, and a property cannot be of both types.
Data descriptors -
value or writable or bothconfigurable,enumerableSample:
{
value: 10,
writable: true;
}
Accessor descriptors -
get or set or bothconfigurable, enumerableSample:
{
get: function () {
return 10;
},
enumerable: true
}
configurable,enumerable and writable:
false.