as3 支持函数的不定参数

      :: Flash :: 2006-6-6 10:52
这里有官方文档的详细说明,关于如何使用... (rest) parameter

livedocs.macromedia.com/labs/1/flex20beta3/langref//statements.html#..._(rest)_parameter


package {
import flash.display.MovieClip;

public class RestParamExample extends MovieClip {
public function RestParamExample() {
traceParams(100, 130, "two"); // Output: 100,130,two
trace(average(4, 7, 13)); // Output: 8
}
}
}


function traceParams(... rest) {
trace(rest);
}

function average(... args) : Number{
var sum:Number = 0;
for (var i:uint = 0; i < args.length; i++) {
sum += args[i];
}
return (sum / args.length);
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}