
arguments.length Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
442
|
ActionScript Language Reference
// Now call formatTitle() and formatBody() from formatPage()
formatPage();
// Displays: true and true
// Then call formatTitle() directly
formatTitle();
// arguments.caller will be null. Displays: false
We can use caller to execute or identify a calling function and to check whether a func-
tion was called directly or by another function.
Usage
Note that in Netscape 4, JavaScript’s arguments.caller refers to the Arguments object of
the calling function, not the calling function itself. In JavaScript,
arguments.caller is depre-
cated as of version 1.3, and it is not supported by Internet Explorer or later versions of
Netscape.
Bugs
Macromedia’s initial documentation for Flash MX incorrectly claims that arguments.caller
refers to the calling function’s Arguments object. It refers, in fact, to the calling function
itself, not the caller’s Arguments object.
Example
The following code shows a function that aborts itself when called directly, ensuring that it
is only called by a larger routine:
function subFunction () {
if (arguments.caller = = null) {
return "Function cannot be called directly.";
}
// proceed with function...
}
See Also
arguments.callee
arguments.length Property
the number of parameters passed to an argument
Flash 5
read/write ...