Chapter 10. Simulated Classes and Inheritance
Even though JavaScript loosely approximates classes with Function
objects and offers a prototype-based inheritance mechanism that's a
little different from what you may be used to if your background is a
language like Java or C++, Dojo does a fine job of building upon native
JavaScript constructs to simulate classes and class-based inheritance.
This chapter dives into dojo.declare,
the toolkit's vehicle for wiring up classes and inheritance and, in
doing so, paves the way for a solid understanding of the Dijit
infrastructure, which is coming up in Part II.
JavaScript Is Not Java
Before we get into the core discussion of simulating inheritance hierarchies and classes with Dojo, you must first grok that JavaScript is not Java, nor does Dojo try to fight against JavaScript's style and reimplement portions of the JavaScript language under the hood and force a square peg in a round hole—and this is a very good thing! JavaScript is an incredibly dynamic, weakly typed language, while Java is a more strongly typed language with real classes and class-based inheritance hierarchies that are defined at compile time. JavaScript has prototypal inheritance that can be used to simulate classes and is purely interpreted.
By embracing JavaScript for what it is and leveraging its language features in the most complementary way possible, Dojo benefits from enhancements to the language as it evolves, avoids the maintenance that comes hand-in-hand with massive ...
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