HTML and CSS Reference
In-Depth Information
EventDispatcher
.
prototype
.
removeEve ntListener
=
function
function
(
type
,
listener
){
iif
(
this
this
.
_listeners
[
type
]
instanceof
instanceof
Array
){
var
var
listeners
=
this
this
.
_listeners
[
type
];
for
for
(
var
var
i
=
0
,
len
=
listeners
.
length
;
i
<
len
;
i
++
){
iif
(
listeners
[
i
]
===
listener
){
listeners
.
splice
(
i
,
1
);
break
break
;
}
}
}
}
Ornament.js
The
Ornament
class defined in
Ornamant.js
will use
EventDispatcher
as its' base class. In-
stancesof
Ornament
willrepresentthebulbswecreateandthendraganddropontoourChrist-
mas tree.
To inherit all the methods and properties from
EventListener
, we need to create an object
and then set the prototype of the object to
EventDispatcher
. We also need to set the con-
structortobethe
Ornament
functionthatholdsalloftheotherfunctionsinthe
Ornament
class.
It will look something like this:
function
function
Ornament
(
color
,
height
,
width
,
context
) {
...(
all code goes here
)
}
Ornament
.
prototype
=
new
new
EventDispatcher
();
Ornament
.
prototype
.
constructor
=
Ornament
;
Because the
Ornament
class is the heart of this application, it contains many essential proper-
ties that form the basis of how this application will function:
bulbColor
Color of bulb (red, green, blue, yellow, orange, purple).
file
file
Filename of bulb image to load. We generate this name when we know the color of the
bulb.
height
height
Height of bulb image.