Game Development Reference
In-Depth Information
In this example, you check whether the variable is equal to
null
(not pointing to an object). If so,
you create a
Cannon
instance using the
new
keyword, after which the situation in memory is changed
again (see Figure
11-11
).
Cannon
anotherCannon
...
Figure 11-11.
Final situation in memory
It's up to you to decide when you would like to use
null
and
undefined
. Not all programmers do this
the same way. We suggest that you use
undefined
to indicate that a variable doesn't exist and
null
to indicate that the variable exists but doesn't yet refer to any object.
What You Have Learned
In this chapter, you have learned:
How to use inheritance to structure related classes in a hierarchy
How to override methods in a subclass to provide specific behavior for
that class
How to call methods from the superclass, such as the constructor method
null
and
undefined
The meaning of
Search WWH ::
Custom Search