Simulating Classes with Dojo
Now that you've had a moment to ponder some of the various
inheritance possibilities, it's time to introduce the toolkit's
fundamental construct for declaring classes and simulating rich
inheritance hierarchies. Dojo keeps it simple by tucking away all of
the implementation details involved with class declarations and
inheritance behind an elegant little function in Base called dojo.declare. This function is easy to
remember because you're loosely declaring a class
with it. Table 10-1 shows the brief
API.
Table 10-1. dojo.declare API
Name | Comment |
|---|---|
| Provides a compact way
of declaring a constructor function. The |
Tip
As you might suspect, declare builds upon the patterns provided
by functions like extend,
mixin, and delegate to provide an even richer
abstraction than any one of those patterns could offer
individually.
Example 10-5
illustrates how you could use dojo.declare to accomplish an inheritance
hierarchy between a shape and circle. For now, consider this example
as just an isolated bit of motivation. We'll discuss the finer points
momentarily.
Example 10-5. Simulating class-based inheritance ...
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