在方法中使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);

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2021-12-13
  • 2021-07-13
  • 2022-01-02
相关资源
相似解决方案