chapter five
5 Objects
This chapter covers
- Controlling property behavior with descriptors
- Sharing behavior through prototype chains
- Binding this to objects at call time
- Intercepting operations with Proxy objects
- Optimizing performance with V8's hidden classes
There’s a terrible joke that an old lawyer friend always loves telling whenever he gets the chance:
“I Object!”, a defendant screams.
The judge, looking concerned, responds, “No… you human.”
I did warn you that it was terrible! But now that we've covered JavaScript's primary set of data type primitives, it's a great way to introduce the subject of the next part of our exploration of JavaScript data types: objects!
Throughout the previous chapters, we've examined JavaScript's primitive types in isolation. Now we start to put these primitives into action in JavaScript's fundamental organizing structure: objects. Every primitive we've studied becomes a building block:
- Strings and symbols serve as property names and values
- Numbers, booleans, null, undefined all become property values
- The type coercion rules from Chapter 4 control how objects convert to primitives for comparison and display.
- Even the V8 optimization patterns we've seen like SMIs for numbers, pointer tagging for null and undefined, ConsStrings for concatenation, have parallels in how V8 optimizes object property access through hidden classes and inline caches.