AS3 ...(其余的)参数参数

由网友(钟于你)分享简介:我已经测试了以下code:I've tested the following code:function aa(...aArgs):void{trace("aa:", aArgs.length);bb(aArgs);}function bb(...bArgs):void{trace("bb:", bArgs...

我已经测试了以下code:

I've tested the following code:

function aa(...aArgs):void
{
    trace("aa:", aArgs.length);
    bb(aArgs);
}
function bb(...bArgs):void
{
    trace("bb:", bArgs.length);
}
aa(); //calling aa without any arguments.

的输出是:

aa: 0 //this is expected.
bb: 1 //this is not!

当我路过空参数(aArgs)至BB功能; 难道不应该返回0长度是多少?好像功能的BB是治疗传递aArgs非空/非空..

When I pass empty arguments (aArgs) to bb function; shouldn't it return 0 length? Seems like function bb is treating the passed aArgs as non-empty / non-null..

我是什么在这里失踪?

任何帮助是AP preciated。 关于..

Any help is appreciated. regards..

推荐答案

看起来aArgs要去BB()函数将是一个空数组,而是一个数组没有少......我要说的是,输出是可以预期的。我真的不知道,虽然我会怎样不同的格式它虽然以获得所需的输出...

It looks like aArgs going to the bb() function would be an empty array, but an array none the less... I would say that output is to be expected. I'm not really sure though how I would format it differently though to get the desired output...

更新1:

我想澄清一点。你有什么是基本相同的事情:

I wanted to clarify a little bit. What you have is basically the same thing as:

function aa(...aArgs):void
{
    myArray:Array = aArgs;
    bb(myArray);
}
function bb(...bArgs):void
{
    trace("bb:", bArgs.length);
}
aa(); //calling aa without any arguments.

如果您看到这个code,你会期望BB:1是

If you saw this code, you would expect bb:1 yes?

更新2:

此主题:http://stackoverflow.com/questions/636853/filling-in-rest-parameters-with-an-array看起来好像是相关的。它采用了适用()函数传递一个数组作为参数列表。 http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#apply()

This thread: http://stackoverflow.com/questions/636853/filling-in-rest-parameters-with-an-array looks as though it would be relevant. It uses the apply() function to pass in an array as an parameter list. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#apply()

阅读全文

相关推荐

最新文章