Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 4. Objects > 4.2 Object Values - Pg. 43

4.2 Object Values 43 4.2 Object Values The following two facts about objects are essential to understanding how to use objects correctly and efficiently, and should be memorized: 1. Every evaluation of an object literal creates a brand-new object. 2. The value of an object literal expression is not really the object itself, but rather a reference, or pointer, to it. We need to tell this story in pictures. Figure 4.1 shows the result of executing a script that declares three variables and creates two objects. Note how the two object facts are reflected in the figure: 1. Because two separate object literals are evaluated, two distinct ob- jects are created, even though each object contains the same proper- ties with the same values. 2. Although the code seems to suggest the objects themselves are stored inside the variables, the variables contain only references. The use of references means that one object can be simultaneously referred