June 2018
Beginner
288 pages
6h 31m
English
Unlike class-based inheritance, prototypal inheritance is implemented using delegation. Remember the sage advice from good design books: delegation is better than inheritance. Prototype-based languages like JavaScript take that advice to heart. Although languages like Java, C#, C++, Ruby, and a number of other OO languages provide class-based inheritance, prototype-based languages use an object chain to delegate calls. Instead of relying on a base class or superclass, prototypal inheritance relies on an object next in the chain to serve as its base. Class-based inheritance is rather inflexible—once you inherit your class from another class, it’s stuck to the parent. In prototype-based languages, inheritance ...