
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
88
|
Chapter 4: Classes
However, using this when not required is redundant. For the sake of easier reading,
many developers (and this book) avoid redundant uses of
this. Even the single-line
getArea( ) method is much less verbose without
this:
function getArea ( ):Number {
return width * height;
}
Methods that make redundant use of this require more work to produce and take
longer to read. However, some programmers prefer to always use
this when refer-
ring to instance properties and methods, simply to distinguish them from local vari-
ables. Other programmers prefer to use variable name prefixes instead, where local
variable names start with
l_, and all property and method names start with m_
(meaning member).
In ActionScript 1.0, within method and constructor function bodies,
the
this keyword was not redundant—it was a required part of all
instance property and method references.
Inside an ActionScript 2.0 class definition, use of the this keyword is legal only
within instance methods and constructor functions. Within a class method (dis-
cussed in the next section), use of the
this keyword generates the following compile-
time error:
'this' is not accessible from this scope.
And anywhere else in a class definition, use of the this keyword generates this error:
This statement is not permitted in ...