CHAPTER 6 Objects
Recall from §3.7 that objects are mutable and are manipulated by reference rather than by value. If the variable x refers to an object, and the code var y = x; is executed, the variable y holds a reference to the same object, not a copy of that object. Any modifications made to the object through the variable yare also visible through the variable x.
The most common things to do with objects are create them and to set, query, delete, test, and enumerate their properties. These fundamental operations are described in the opening sections of this chapter. The sections that follow cover more advanced topics, many of which are specific to ECMAScript 5.
- The writable attribute specifies whether the value of the property can be set.
- The enumerable attribute specifies whether the property name is returned by a for/in loop.
- The configurable attribute specifies whether the property can be deleted and whether its attributes can be altered.
Prior to ECMAScript 5, all properties in objects created by your code are writable, enumerable, and configurable. In ECMAScript 5, you can configure the attributes of your properties. §6.7 explains how to do this.
In addition to its properties, every object has three associated object attributes:
- An object’s prototype is a reference to another object from which properties are inherited.
- An object’s class is a string that categorizes the type of an object.
- An object’s extensible flag specifies (in ECMAScript 5) whether new properties may be added to the object.
- A native object is an object or class of objects defined by the ECMAScript specification. Arrays, functions, dates, and regular expressions (for example) are native objects.
- An own property is a property defined directly on an object.
- An inherited property is a property defined by an object’s prototype object.