
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Other Operators
|
141
}
function Circle ( ) {
// ...
}
// Establish inheritance: Circle is a subclass of Shape
Circle.prototype = new Shape( );
// Create a Circle object
var theCircle = new Circle( );
// Check the class of the Circle object using instanceof
trace(myCircle instanceof Circle); // true
trace(myCircle instanceof Shape); // true
The instanceof operator can be used to operate on an object conditionally, based on
its class. For example, the following code uses instanceof to remove all text fields and
movie clips from the current movie clip (
this):
for (var p in this) {
if (this[p] instanceof MovieClip) {
this[p].removeMovieClip( );
} else if (this[p] instanceof TextField) {
this[p].removeTextField( );
}
}
Note that the instanceof operator simply checks whether object’s prototype chain
includes
classConstructor, as discussed in Chapter 12 under “The Almighty Proto-
type Chain.”
The super “Operator”
Added in Flash MX, super is an operator-like tool that serves two distinct object-
oriented programming purposes:
• It can invoke an object’s superclass constructor.
• It can invoke a superclass’s implementation of an overridden method.
In either case, super can be used only within a class constructor function or a
method.
To invoke an object’s superclass constructor function, use the following ...