Prototypal Inheritance in JavaScript
From the JavaScript cheat sheet · Prototypes & Inheritance · verified Jul 2026
Prototypal Inheritance
Implementing inheritance with prototypes
javascript
// Constructor inheritance
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
return `${this.name} makes a sound`;
};
function Dog(name, breed) {
Animal.call(this, name); // super constructor
this.breed = breed;
}
// Set up inheritance
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;💡 Use Object.create() to set up prototype chain
⚡ Don't forget to reset constructor after changing prototype
📌 Call parent constructor with ParentConstructor.call(this)
🔥 Classes (ES6) provide cleaner syntax for same behavior