
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Function Parameters Revisited
|
199
The rules for creating timeline variables apply even if our function is a method of an
object. We won’t cover objects until Chapter 12, but for those familiar with object-
oriented programming, Example 9-2 shows code that proves the point. Observe that
x is defined on the timeline because it doesn’t exist in the local scope of newFunc( ).
Using unqualified variable references inside functions to affect timeline variables may
appear handy, but more often than not it is confusing, particularly in large projects.
It’s wise to take the ambiguity out of variable access by using qualified variable refer-
ences (i.e., prefix the variable with an explicit object reference, such as
this.x versus
x, as discussed in Chapter 2 under “Accessing Variables on Different Timelines”).
Function Parameters Revisited
Now that we’re comfortable with how functions work, let’s return to the topic of
function parameters. Our current discussion requires a little knowledge of objects, so
new programmers may want to read Chapter 12 before reading this section.
Number of Parameters
Earlier we saw that the parameters of a function are declared when the function is
created. Recall the syntax:
function funcName (param1, param2, ...paramn) {
statements
}
Perhaps surprisingly, the number ...