在 AS3 方法中接受多个参数 [英] Accept multiple arguments in an AS3 method

查看:28
本文介绍了在 AS3 方法中接受多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在自定义方法中接受多个参数?喜欢:

How do I accept multiple arguments in a custom method? Like:

Proxy(101, 2.02, "303");

function Proxy(args:Arguments){
    Task(args);
}

function Task(var1:int, var2:Number, var3:String){ 
    // work with vars
}

推荐答案

您不能像在问题中那样只传递 args 数组.您必须单独传递 args 数组的每个元素.

You wouldn't be able to just pass the args array through like you have in your question. You'd have to pass each element of the args array seperately.

function Proxy(... args)
{
   // Simple with no error checking.
   Task(args[0], args[1], args[2]);
}

Udate

阅读其中一条评论后,您似乎可以逃脱:

After reading one of the comments, it looks like you can get away with:

function Proxy(... args)
{
    // Simple with no error checking.
    Task.apply(null, args);

    // Call could also be Task.apply(this, args);
}

小心点.apply() 的性能明显比用传统方法调用函数慢.

Just be careful. Performance of apply() is significantly slower than calling the function with the traditional method.

这篇关于在 AS3 方法中接受多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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