Lesson 1 of 6

Property lookup and the chain

A browser object is a thing with helpers behind it.

When you call something like button.appendChild(...), the browser first looks at the button itself. If the button does not own that method, the browser walks upward through its prototypes.

paragraph

1. Pick one thing

2. Ask for a method or property

3. The browser searches in this order

Start with the actual thing, then move upward one prototype at a time.

Why is Object.keys not on Object.prototype?

Methods on Object.prototype

These are called from a normal object.

person.hasOwnProperty("name")
person.toString()

Methods on Object

These are utility functions. You pass the object in.

Object.keys(person)
Object.values(person)

Plain-English words

Object
A value with properties. A button, the document, and { name: "Ada" } are all objects.
Property
A named thing on an object, like button.disabled or input.value.
Method
A property that is a function, like button.click().
Prototype
A backup object the browser checks when the thing itself does not have what you asked for.
Prototype chain
The full backup path: button, then HTMLButtonElement, then HTMLElement, then Element, and so on.