liveBook · Manning

Property lookup

As explained in JavaScript in Depth

The JavaScript procedure for resolving a property by checking an object and then traversing its prototype chain.

A property read and a write can target different objects. A read checks the object, follows its [[Prototype]] chain when necessary, and may find an inherited value; a write can instead create an own property that shadows that value. section 5.3.1

The lookup process proceeds as follows:

  • Check the current object for an own property descriptor. section 5.3.1
  • Return a data property's value, or invoke an accessor property's getter with the original receiver. section 5.3.1
  • If absent, follow [[Prototype]] until finding the property or reaching null; ordinary chains commonly pass through Object.prototype. section 5.3.1

Inherited label becomes shadowed

const drawerPrototype = { label: 'default' }; const drawer = Object.create(drawerPrototype); drawer.label reads 'default'. After drawer.label = 'tax documents', drawer owns a new label while drawerPrototype.label remains 'default'.

How JavaScript in Depth covers it

How deep it goes
Traces own descriptors, data properties, accessors, prototype traversal, and null termination, while distinguishing reads from writes.
Examples
Uses drawer objects, inherited labels, accessor setters, authorization checks, and inherited configuration defaults.
What you can do after
Diagnose inherited-property bugs by inspecting descriptors and prototype chains with Object.getOwnPropertyDescriptor and Object.getPrototypeOf.
How it connects
Connects property lookup to prototype chains, shadowing, accessors, property descriptors, and Object.prototype.

Also explained in

Compare how 2 books explain property lookup →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.