
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
292
|
Chapter 12: Objects and Classes
When defining a property that will hold a constant value, it is also perfectly legiti-
mate to use the class’s
prototype property, as follows:
function Square ( ) {
statements
}
Square.prototype.numSides = 4;
However, this approach demands that numSides be accessed through an instance of
Square, not through the Square class directly. If you want to use a property without
first creating an instance of a class, you should make that property static.
Sometimes, static properties and methods are used to package a series of related con-
stants and functions into a class that will never be instantiated. In ActionScript, this
is normally achieved by adding properties and methods to a generic instance of the
Object class. For example, the Math, Key, Mouse, and Stage objects are implemented
in this manner.
For the benefit of Java programmers, Table 12-1 outlines the rough equivalencies
between Java and ActionScript methods and properties.
Inheritance: Superclasses and Subclasses
One of the crucial features of classes in advanced object-oriented programming is
their ability to inherit properties and methods. That is, an entire class can adopt the
properties and methods of another class and add its own specialized features. The
class that borrows the properties and ...