大步前行

不管前方有什么,好在有人支持,大步向前走就对了

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
在方法中使arguments数组,一般情况下,方法需要的参数都是在参数定义时写出的,但是有些特定的情况下,参数的个数是未知的,在这种情况下,就可以使用flash内建的arguments数组,所以向方法传递的参数都被自动的放入arguments数组中
例:// There is no need to specify the parameters to accept when using the 
// arguments array.
private function average(  ):Number {
  
var sum:Number = 0;

  
// Loop through each of the elements of the arguments array, and 
  // add that value to sum.
  for (var i:int = 0; i < arguments.length; i++) {
    sum 
+= arguments[i];
  }
  
// Then divide by the total number of arguments
  return sum/arguments.length;
}

// You can invoke average(  ) with any number of parameters. 
var average:Number = average (12510820);
posted on 2009-05-13 15:39  大步前行  阅读(494)  评论(0编辑  收藏  举报