
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
98
|
Chapter 4: Classes
checking), it pays to use the accessor everywhere, even within the class that defines
the property. For example, remember that we modified our earlier setWidth( )
method to include error checking for invalid data. Whenever we assign the value of
width within the Box class, we still want the benefit of setWidth( )’s error checking.
That is, although accessing properties directly from within a class conforms to OOP
guidelines, it’s sensible to use the accessor methods instead.
If you simply prefer the style of direct property access but still want
the benefits of accessor methods, you should consider using Action-
Script 2.0’s automatic getter and setter methods, discussed later.
Local Variables
We’ve seen that instance properties are associated with each instance of a class and
that class properties are associated with the class itself. Instance and class properties
persist as long as the object they’re associated with persists. But often you’ll need a
variable only temporarily. A local variable is a temporary data container used to store
a value for the duration of a function or method execution. Local variables can be
defined within a function or method only and are normally marked for automatic
deletion when the function or method finishes executing (we’ll learn ...