
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
306
|
Chapter 12: Objects and Classes
Box.numSides = 4;
var bigBox = new Box( );
trace(bigBox.constructor.numSides); // Displays: 4
In ECMA-262, JavaScript, and ActionScript, the constructor property
is written to a class’s prototype (as
Class.prototype.constructor),
where instances of the class can retrieve it via the prototype chain.
However, ActionScript also adds a
constructor property directly to
instances (as
instanceName.constructor) effectively obscuring Class.
prototype.constructor. ActionScript’s nonstandard implementation is
considered a bug by Macromedia—the ECMA-262 standard requires
that an instance retrieve its constructor via
Class.prototype.
constructor
. In a future version of Flash, Macromedia will likely fix
this bug (that is, in the future
constructor will no longer be written
directly to instances). We’ll see how writing a
constructor property to
individual instances affects inheritance in the next section.
Advanced Issues with Standard SuperClass Assignment
As we’ve seen, the standard means for establishing a class’s superclass is:
SubClass.prototype = new SuperClass( );
When using the new operator to establish inheritance, some developers have encoun-
tered minor problems, discussed in detail next. To sidestep these problems, some
developers use the following unofficial technique, ...