Multiply Inheriting with Mixins
The previous section introduced how Dojo simulates class-based
inheritance and pointed out some critical issues involving
JavaScript's finer points that are central to developing with Dojo.
Although the primary example demonstrated single inheritance in which
a Shape superclass provided the
basis for a Circle subclass, Dojo
also provides a limited form of multiple inheritance.
The process of defining inheritance relationships by weaving
together Function objects in this way is referred to as
prototype chaining because it's through
JavaScript's Object.prototype
property that the hierarchy is defined. (Recall that Example 10-2 illustrated this
concept within the boilerplate of manually defining an inheritance
relationship between a shape and a circle.)
Dojo simulates class-based inheritance by building upon the
concept of prototype chaining to establish the hierarchy for single
inheritance contexts. However, employing multiple-inheritance
relationships is a little bit different because JavaScript limits
Function objects to having only one built-in prototype property.
As you might imagine, there are a number of approaches that could be used to circumvent this issue. The approach that Dojo uses is to leverage prototype chaining so that you define a single prototypical ancestor that is the basis for prototype chaining—but at the same time, allowing you to provide other mixins that get injected into the prototypal ancestor. In other words, a class can have ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access