Property lookup determines which value JavaScript returns when code reads an object property or invokes a method. The engine checks the object first. If the property is absent, it follows the object’s internal [[Prototype]] link and repeats the search up the prototype chain. A local property wins; an inherited property remains available through the same access syntax. section 2.1.1 section 1.2
A property found on a prototype
const transaction = { sender: 'luis@tjoj.com' }; const moneyTransaction = Object.create(transaction); moneyTransaction.funds = 10; moneyTransaction.funds; // 10: found locally moneyTransaction.sender; // 'luis@tjoj.com': found on transaction Object.create links the new object to transaction; it does not need to copy sender onto the new object. section 2.1 section 2.1.1
Lookup continues through linked objects as far as Object.prototype. If no value is found, a property read yields undefined; attempting to invoke a missing method produces a TypeError. Use Object.create to establish a link and Object.getPrototypeOf to inspect it rather than manipulating __proto__ directly. section 2.1.1 section 2.1
The same mechanism lets constructor-created instances share methods through their prototypes. An incorrectly configured prototype chain can therefore make a method appear to be missing even when it was defined on a constructor’s prototype. Linked objects can also specialize a parent by adding properties or overriding inherited ones; changes higher in a chain can affect derived objects at runtime. section 2.2.2 section 2.1.2 section 1.2
Module design offers a useful contrast: calls on a CommonJS module object use ordinary property resolution, whereas the static structure of an ECMAScript module allows named lookups to be resolved ahead of time. section 6.5.2
