Combination Inheritance
Combination inheritance (also called pseudo‑classical inheritance) combines prototype chain inheritance and constructor stealing. It allows inheriting both instance properties (with their own copies) and shared methods via the prototype.
Code Example
Section titled “Code Example”function Parent(name) { this.name = name; this.colors = ["red", "blue"];}Parent.prototype.greet = function () { console.log(`Hello ${this.name}`);};
function Child(name, age) { Parent.call(this, name); // inherit instance properties this.age = age;}Child.prototype = new Parent(); // inherit methodsChild.prototype.constructor = Child; // fix constructor reference
const child1 = new Child("John", 10);child1.colors.push("green");console.log(child1.colors); // ["red", "blue", "green"]child1.greet(); // "Hello John"
const child2 = new Child("Jane", 12);console.log(child2.colors); // ["red", "blue"]