What is the Prototype pattern?
By FrontendPro Editorial Team Updated 9/26/2026
Answer
The Prototype pattern creates new objects by cloning an existing one rather than constructing from scratch. You keep a fully configured instance around and copy it whenever you need another — useful when setting an object up is expensive or when the configuration is easier to copy than to describe again.
JavaScript supports this directly, since objects already delegate to a prototype:
const buttonPrototype = {
size: "medium",
variant: "primary",
render() {
return `<button class="${this.size} ${this.variant}">${this.label}</button>`;
},
};
const saveButton = Object.create(buttonPrototype);
saveButton.label = "Save";
const cancelButton = Object.create(buttonPrototype);
cancelButton.label = "Cancel";
cancelButton.variant = "ghost"; // override just this one
Object.create links rather than copies: saveButton stores only label, and everything else is found on the prototype. Add a method to buttonPrototype later and both buttons get it immediately.
Linking versus copying
If you want an independent copy instead of a live link, use spread or structuredClone:
const copy = { ...original }; // shallow — nested objects still shared
const deep = structuredClone(original); // deep, handles Dates, Maps, cycles
Shallow copying is the usual source of bugs here: mutating copy.settings.theme also changes the original, because both point at the same nested object.
Is it worth naming?
In languages without prototypes this is a genuine pattern. In JavaScript it is close to how the language already works, so you rarely invoke it deliberately. It is still worth recognising the name, and Object.create(null) has a practical use of its own — an object with no prototype at all, safe to use as a dictionary without inherited keys like toString getting in the way.
