Understanding the prototypal inheritance model

Each JavaScript object has an internal [[prototype]] property pointing to another object called its prototype. This prototype object has a prototype of its own, and so on, until an object is reached with null as its prototype. null has no prototype, and it acts as a final link in the prototype chain.

When trying to access a property of an object, and if the property is not found in the object, then the property is searched for in the object's prototype. If still not found, then it's searched for in the prototype of the prototype object. It keeps on going until null is encountered in the prototype chain. This is how inheritance works in JavaScript.

As a JavaScript object can have only one prototype, ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.