Datasheet
Chapter 1: Enhancing Development with Dojo Core
This sets the base URL for all modules loaded with relative paths, which exclude those that are part of
the Dojo XDomain build — because those modules in the XDomain build all have absolute paths to the
AOL CDN ‘‘burned in’’ as part of the build process for that version of Dojo.
And, because you’re now up to two settings in
djConfig
, it’s worth noting that you can also define
djConfig
more fully in a JavaScript block rather than an attribute:
<script type="text/javascript">
djConfig = {
isDebug: true,
parseOnLoad: true,
baseUrl: ‘./’,
modulePaths: {
"decafbad": "./decafbad",
},
};
</script>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"></script>
Notice that the
dojo.registerModulePath()
call can be replaced by defining
modulePaths
in
djConfig
.
This offers a bit more clarity and efficiency up front if you know you’re going to define a series of paths,
or if you’ll be doing a bit of advanced Dojo configuration anyway.
More About Dojo XDomain Builds
To avoid a lengthy digression, this chapter glosses over the Dojo build system. The
build system is covered in a later chapter — but if you’d like to know about XDomain
builds in particular, read more here:
http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/
package-system-and-custom-builds
Defining Classes and Using Inheritance
Something that’s important to understand about JavaScript is that although it does deal with objects, it’s
a prototype-based language. It doesn’t natively offer classes and inheritance like other languages focused
on object-oriented programming. In many ways, a prototype-based language can be more expressive
because multiple forms of code re-use can be employed — including classes and inheritance — but with
the caveat that you need to implement those facilities yourself.
Defining Classes with dojo.declare()
With that in mind, consider the following code defining a JavaScript class the usual way:
decafbad.school.PersonClassic = function(name) {
this.name = name;
};
decafbad.school.PersonClassic.prototype = {
11