Java Reference
In-Depth Information
Table 4-10.
The List of Property Attributes and Their Descriptions
Attribute
Type
Applicable To
Description
value
Any type
Data Property Only
The value of the property
writable
Boolean
Data Property Only
Specifies whether the value of
the property can be changed.
If
false
, the property is read-
only. Otherwise, the property is
read-write. The default is
true
get
function
Accessor Property Only
The getter method for the
property or
undefined
. The
default is
undefined
set
function
Accessor Property Only
The setter method of the property
of
undefined
. The default is
undefined
enumerable
If set to
false
, the property of
the object cannot be enumerated
using the
for..in
and
for..
each..in
loops. The default is
true
Boolean
Both
configurable
Boolean
It set to
false
, the property
cannot be deleted and attributes
for the property cannot be
changed. The default is
true
Both
You can read and set the property attributes using an object called the property
descriptor. The following statement create a property descriptor that has the
value
property to 10 and
writable
property to
false
:
var descriptor = {value:10, writable:false};
Creating a property descriptor does not do anything. It just creates an object. You
need to use one of the following three methods of
Object
to define a new property
with attributes, to change the attributes of an already defined property, and to read the
property descriptor of an existing property:
Object.defineProperty(object, "propertyName",
propertyDescriptor)
•
Object.defineProperty(object, "propertyName",
attributeObject)
•
Object.getOwnPropertyDescriptor(object, "propertyName")
•
Search WWH ::
Custom Search