Prototype chain
The lookup path JavaScript follows for missing properties.
Prototypes are JavaScript’s delegation system. Objects can read properties and methods from another object through the prototype chain.
const base = {
describe() { return this.title; }
};
const item = Object.create(base);
item.title = "Overview";
Objects, Prototypes & Classes
Every normal object has a prototype. When JavaScript cannot find a property directly on the object, it looks up the prototype chain.
Constructor functions and classes use prototypes so instances can share methods instead of copying the same function to every object.
Prototype delegation is powerful, but it should be used clearly. Most application code uses object literals, classes or Object.create instead of manually changing prototype chains.
The lookup path JavaScript follows for missing properties.
A property stored directly on the object.
A method found on the prototype instead of each instance.
Creates an object with a chosen prototype.
Examples
const baseRecord = {
label() {
return this.title;
}
};
const record = Object.create(baseRecord);
record.title = "Overview";
const record = { title: "Overview" };
Object.setPrototypeOf(record, baseRecord);
// This is usually slower and harder to reason about.
Code patterns
These patterns focus on the pieces developers actually reuse: object literals, methods, constructors, prototypes, getters, copying, classes and inheritance.
Create an object that delegates to a base object.
const baseRecord = {
label() { return this.title; }
};
const record = Object.create(baseRecord);
record.title = "Overview";
Check whether a property exists directly on the object.
const record = { title: "Overview" };
console.log(Object.hasOwn(record, "title"));
Inspect the prototype of an object.
const record = { title: "Overview" };
console.log(Object.getPrototypeOf(record));
Instances delegate to the constructor prototype.
function Record(title) { this.title = title; }
Record.prototype.label = function () { return this.title; };
const record = new Record("Overview");
Rules that matter
Objects are where JavaScript programs start to model real application state. Good object shape makes later functions, classes and UI updates much easier to maintain.
Missing properties are searched on the prototype chain.
Object.hasOwn checks direct properties.
This saves memory for many similar objects.
It can hurt performance and readability.
Class syntax writes prototype methods cleanly.
Changing global behavior can break other code.
Production thinking
Prototypes explain why class methods are shared and why objects can appear to have methods that are not stored directly on them.
Shared UI model methods should still produce predictable labels and states when accessed through prototypes.
Production code should avoid prototype tricks unless there is a clear architectural reason.
Prototype-based content models must produce stable visible text when methods are inherited.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Object-oriented JavaScript becomes much easier when you can explain where the data lives, where the method is found and which object receives this.
Senior audit upgrade
JavaScript looks for a property on the object first, then walks up the prototype chain.
object -> object prototype -> Object.prototype -> null