JavaScript is essentially a data structure that stores key-value pairs, but unlike maps and dictionaries, JavaScript objects are highly configurable.
When an object is created and properties are added to that object, each property has a default property descriptor associated with it. A property descriptor is a javascript object that contains some information about the corresponding property, such as value
.
Object.getOwnPropertyDescriptor
To get the property descriptor of a property, you can use the static method Object.getOwnPropertyDescriptor
of Object
.
|
|
The object returned by Object.getOwnPropertyDescriptor
is the property descriptor, and the property descriptor contains the following properties to describe the object properties associated with it.
value
: the current value of the propertywritable
: indicates whether the assignment of a value to a property is allowedenumerable
: indicates whether the property is enumerable.true
means that the property is enumerable, then the property will appear infor in
andfor of
loops or inobject.keys
.configurable
: indicates whether the property is configurable,true
means that the user has permission to change the value in the property descriptor of the property, such as the values ofwritable
andenumerable
,false
means that it is not configurable and has no permission.
Object.defineProperty
You can define a new property for an object or update the descriptor of an existing property by using Object.defineProperty.