这里有官方文档的详细说明,关于如何使用... (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);
}
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);
}
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}