Datasheet

Chapter 1: Enhancing Development with Dojo Core
an anonymous function to each of them. The final parameter,
this
, causes the anonymous function to
execute in the context of the object being constructed.
With each
<span>
, the anonymous function examines the class name and attempts to update its
innerHTML
property with a representation of the object property bearing the same name. So, if there’s a
<span class
=
"alpha">
, it should be changed to represent the type and contents of
this.alpha
if such
a property has a value in the object. Otherwise, the
<span>
should read ‘‘undefined.’’
Seeing Markup Object Declaration in Action
Putting it all together, check out Figure 1-5 to see what this code should end up doing.
Figure 1-5
Here are some things to notice about the output and what happened:
Thanks to the
dojoType
=
"decafbad.things.thingA"
attribute in the markup, an instance of
decafbad.things.thingA
was created by the Dojo parser on page load.
Due to
jsId
=
"decafbad.stuff.someThingA"
, other code will be able to refer to this newly
instantiated object as
decafbad.stuff.someThingA
.
Each attribute on the
<div>
was handed to the constructor for
decafbad.things.thingA
in a
single JavaScript object, with type conversions to match the default values of properties existing
in the class declaration.
As part of constructing the
decafbad.things.thingA
instance, the contents of the
<div>
declar-
ing the object were modified to reflect the properties of the new instance.
Oh, and there’s one more thing: The property
xyzzy
appears to be undefined.
That last item is true because not all of the attributes from the markup were converted and passed to the
constructor. Take a look at the implementation for
decafbad.things.thingA
again, and you may notice
that
xyzzy
is missing from the list of properties in the class declaration.
Because the parser does introspection into the properties and their types defined by the class decla-
ration, it converts and provides data only for those attributes named in the declaration. So, although
xyxxy
— and even
class
— appear as attributes on the object declaration
<div>
, they’re not given to the
17