Java Reference
In-Depth Information
It's often a useful exercise to override the toString() method using the prototype ob-
ject, so that something more meaningful is displayed. For example, we could edit the
Turtle() prototype object so that it's more descriptive:
Turtle.prototype.toString = function() {
return "A turtle called " +;
<< "A turtle called Michelangelo"
The toString() method is a good demonstration of polymorphism, since different ob-
jects have the same method but implement it differently. The advantage of this is that
higher-level functions are able to call a single method, even though it may be implemented
in various ways.
Property Attributes and Descriptors
We've already seen that all objects are collections of key-value paired properties. It turns
out that each property has a number of attributes that provide information about the prop-
erty. These attributes are stored in a property descriptor , which is an object that contains
values of each attribute.
All object properties have the following attributes stored in a property descriptor:
value - this is the value of the property and is undefined by default
writable ― this Boolean value shows whether a property can be changed or
not, and is false by default
enumerable ― this Boolean value shows whether a property will show up when
the object is displayed in a for in loop, and is false by default
configurable ― this Boolean value shows whether you can delete a property
or change any of its attributes, and is false by default
Search WWH ::

Custom Search