开发者

Actionscript function definition

开发者 https://www.devze.com 2023-01-27 03:24 出处:网络
How ca开发者_运维百科n I define functions that can receive unknown/variable amount of parameters? It is called rest parameter, Use this:

How ca开发者_运维百科n I define functions that can receive unknown/variable amount of parameters?


It is called rest parameter, Use this:

function getItems(...rest):void
{
    // ... logic goes here
}

Inside the function you deal with rest as the name of the array.

When creating a rest parameter you should keep these in mind:

  • Rest parameters are untyped. It is up to you to validate any special type requirements as you loop through the rest parameter array.
  • Rest parameters must be at the end of a method's parameters.
  • The rest parameters must have ... in front of it, but the variable name can be anything.


private function someFunction(...args) : void
{
  for(var i : int = 0; i < args.length ; i++)
  {
     trace(i, args[i]);
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消