AS3 ...(其余的)参数 [英] AS3 ... (rest) parameter

查看:209
本文介绍了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.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:

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

这篇关于AS3 ...(其余的)参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆