What is the prototype pattern?

JavaScript

The short answer

The prototype pattern creates new objects by cloning an existing object (the prototype) instead of creating from scratch. In JavaScript, this is built into the language — every object has a prototype, and you can create new objects that inherit from existing ones using Object.create.

How it works

const carPrototype = {
start() {
console.log(`${this.make} ${this.model} started`);
},
stop() {
console.log(`${this.make} ${this.model} stopped`);
},
};
function createCar(make, model) {
const car = Object.create(carPrototype);
car.make = make;
car.model = model;
return car;
}
const honda = createCar('Honda', 'Civic');
const toyota = createCar('Toyota', 'Corolla');
honda.start(); // "Honda Civic started"
toyota.start(); // "Toyota Corolla started"

Both honda and toyota share the same start and stop methods through the prototype. The methods are not copied — they are inherited.

Why use it

Memory efficiency: If you create 1000 car objects, the start and stop methods exist only once (on the prototype), not 1000 times.

Easy to extend: Adding a method to the prototype gives it to all objects:

carPrototype.honk = function () {
console.log('Beep!');
};
honda.honk(); // "Beep!" — available immediately
toyota.honk(); // "Beep!"

Prototype pattern vs class

The prototype pattern is what JavaScript classes do under the hood:

class Car {
constructor(make, model) {
this.make = make;
this.model = model;
}
start() {
console.log(`${this.make} ${this.model} started`);
}
}

start lives on Car.prototype, not on each instance. The class syntax is just a cleaner way to write the prototype pattern.

Interview Tip

The key point is that the prototype pattern avoids duplicating methods across instances — they are shared through the prototype chain. Show a simple Object.create example and mention that JavaScript classes are syntactic sugar for this pattern.

Why interviewers ask this

This tests if you understand how JavaScript's prototype system works at a fundamental level. The prototype pattern is not just a design pattern — it is how the language itself works. Understanding it helps you reason about inheritance, method lookup, and memory usage.