JS Built-ins
Prototypesbeginner

Prototypes β€” Methods from prototype

πŸ“– Usage Example
const proto = { greet() { return 'hello'; } };
const obj = Object.create(proto);
obj.greet(); // found via prototype chain

JavaScript walks up the prototype chain to find properties not on the object itself.

Accessing Methods Through the Prototype Chain

When you access a property or method on an object, JavaScript first looks on the object itself. If not found, it searches the prototype. This is the foundation of prototype-based inheritance.

Challenge: Create an object that inherits a method from its prototype without having the method as its own property.

πŸ’‘ Hints (2)
  • β€’ Use Object.create() to set up the prototype chain
  • β€’ Properties not found on object are looked up on prototype