AS3 ...(休息)参数 [英] AS3 ... (rest) parameter

查看:23
本文介绍了AS3 ...(休息)参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经测试了以下代码:

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..

我在这里遗漏了什么?

感谢任何帮助.问候..

Any help is appreciated. regards..

推荐答案

看起来去 bb() 函数的 aArgs 将是一个空数组,但仍然是一个数组......我会说输出是被期望.我不太确定我将如何以不同的方式对其进行格式化以获得所需的输出...

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.

如果您看到此代码,您会期望 bb:1 是吗?

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

更新 2:

此线程:用数组填充 (...rest) 参数? 看起来好像是相关的.它使用 apply() 函数将数组作为参数列表传入.http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#apply()

This thread: 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天全站免登陆