Package Top Level
Class public class arguments
Inheritance arguments Inheritance Object
简要介绍[主要是翻译API, 寒]:
一个Arguments类主要用来存储与访问一个函数的参数, 在函数体内, 可以通过本地参数变量来访问Arguments对象.
Arguments对象存储形式为数组, 因此,arguments[i]即代表了第i个参数(前提时有这么多参数….)
相对与之前的ActionScript版本,ActionScript3.0中不再使用Arguments.caller[之前的版本没用过:(], 在3.0中, 如果需要访问调用该参数的函数, 则可以使用arguments.callee.
Public Properties[不知道该咋翻译, 继续寒]:
callee:Function 返回调用该参数的当前函数
length: Number 参数数目[ 即参数作为数组的长度]
举例: [小修改了下API里的例子]
在初始化时运行 ArgumentsExample(1,’ss’);
import flash.display.Sprite;
private var count:int = 1;
public function ArgumentsExample(i:int, s:String):void {
//参数以数组形式存放于arguments中.
trace("第一个参数: " + arguments[0] + " 第二个参数: " + arguments[1] + " 共有 " + arguments.length + "个参数.");
trace(arguments.callee == this.ArgumentsExample);
firstFunction(true);
}
public function firstFunction(callSecond:Boolean):void {
trace(count + ": firstFunction");
if(callSecond) {
//调用secondFunction, 参数为firstFunction
trace(arguments.callee);
}
else {
trace("CALLS STOPPED");
}
}
public function secondFunction(caller:Function):void {
trace(count + ": secondFunction");
count++;
//此时caller即firstFunction, 实际运行为firstFunction(false);
caller(false);
}
运行结果:
第一个参数: 1 第二个参数: ss 共有 2个参数.
true
1: firstFunction
1: secondFunction
2: firstFunction
CALLS STOPPED




专业博客点击率老高咯哦~