
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
84
|
Chapter 4: Classes
types, in practice nothing in the method invocation expression can sufficiently indi-
cate which return type (and hence, which method) is required. Thus, the return
datatype is not used to identify a method’s signature, but simply to perform type
checking on the return types.
Returning to our getArea( ) method, note that the whitespace adjacent to the curly
braces in our getArea( ) definition is not dictated by ActionScript’s grammatical
rules; it’s a matter of personal style. Some developers place the opening curly brace
on the first line of the method definition, as shown earlier and throughout this book.
Others place it on a line of its own, as in:
function getArea ( ):Number
{
return width * height;
}
Both styles are technically valid; only you can decide which god you pray to.
Referring to the Current Object with the Keyword this
From within a method body, you’ll often want to refer to the object on which the
method was invoked—the so-called current object. Consider the expression
b.
getArea( )
. When that code runs, it invokes getArea( ) on the object b, but within the
getArea( ) method body there is no such variable as
b. So how do we refer to the cur-
rent object—the object on which getArea( ) was invoked—from within getArea( )?
To refer to the current object ...