Skip to the workspace
Pebellslearn by building
Data Types  ›  Lesson

Object Prototype and Prototypal Inheritance

Object Prototype 12 min

javascript / Object Prototype and Prototypal Inheritance

Explore each scene at your own pace.

01 · Object Prototype and Prototypal Inheritance

Object Prototype and Prototypal Inheritance

Object Prototype and Prototypal Inheritance

Prototype lookup checks an object’s own properties and then follows its prototype chain until it finds the property or reaches null.

Sharing behavior through a prototype does not copy that behavior into every object.

See the mechanism

Walk through the modelObject Prototype and Prototypal InheritanceAuthored snapshots of the example; use Run below to test the code.
Statearticle owns title
Stateno own category
The requested category is not found on the instance.
1 of 3

Follow one example

javascript

The first category read falls back to defaults. It is not an own property of article. Assigning article.category creates an own property for this ordinary writable case and shadows the inherited value; defaults.category remains General. Avoid confusing an object’s internal prototype link with an ordinary property named prototype on constructor functions.

Predict, change and check

Predict: After creating article.category, will deleting that own property reveal the inherited category again?

Test your explanation: Delete article.category and read it. Compare the result with deleting defaults.category instead.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Reading a missing own property can follow the object's internal prototype chain until it finds a property or reaches null. Adding an own property can shadow an inherited one; deleting that own property can reveal the inherited value again. The behavior depends on descriptors and accessors as well as the simple writable example.

An object's prototype link is not the same thing as an ordinary constructor function's prototype property. Object.create chooses a prototype for a new object, while new uses constructor behavior and its prototype relationship. Inspect ownership with Object.hasOwn and inspect the actual link with Object.getPrototypeOf instead of using ambiguous labels.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.