You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press

Prototypal Inheritance

The whole terrarium detour should have given you some insight into the way objects are used in real programs. The rest of the chapter is devoted to a more in-depth look at inheritance and the problems related to inheritance in JavaScript.

First, let’s go over some theory. Students of object-oriented programming can often be heard having lengthy, subtle discussions about correct and incorrect uses of inheritance. It is important to bear in mind that inheritance, in the end, is just a trick that allows lazy programmers—and here I mean to use the word lazy in the most positive way possible—to write less code. Thus, the question of whether inheritance is being used correctly boils down to the question of whether the resulting ...

The best content for your career. Discover unlimited learning on demand for around $1/day.