Passing …(rest) parameters between functions
来源:互联网 发布:四库全书数据库 编辑:程序博客网 时间:2024/05/16 18:26
http://www.ericfeminella.com/blog/2008/04/22/passing-rest-parameters-between-functions/
At some point when developing an application with ActionScript 3 you may need to pass a…(rest) parameter to a subsequent function call, and although at first this may appear to be pretty straightforward, doing so will not produce the results one might expect.
For example, consider the following method doSomething
which accepts a single …rest parameter:
Let’s say we also have another function we need to invoke called doSomethingElse
which accepts a …(rest) parameter as well:
Now suppose we need to pass the ...(rest)
parameter from the doSomething
function to the doSomethingElse
function. The result would be as follows:
So what went wrong? What happens is the original …rest parameter (passed to doSomething
) is now being passed as a single parameter of type Array to the subsequent function (doSomethingElse
), not as an Array of individual arguments as you may have expected.
This can easily be resolved by using Function.apply(); as can be seen in the following:
What we are doing is applying the call to the doSomethingElse
function with the original rest parameter as if we were invoking the function directly. So keep this in mind should you ever need to pass a …rest parameter to a subsequent function.
- Passing …(rest) parameters between functions
- Passing pointers to functions
- passing data between Activities
- Mondrian parameters passing to MDX
- C# - Passing Reference-Type Parameters
- Passing Data between View Controllers
- Passing data between view controller.
- Passing Data between View Controllers
- Passing Objects Between Android Activities
- Passing parameters to a Jasper report
- Passing Reference-Type Parameters (C# Programming Guide)
- Passing Server Control Values Between Pages
- 传送数据 Passing Data Between Views (实例)
- Clustering by Passing Messages Between Data Points
- Choosing Between Functions and Macros
- Passing Parameters/Argument to FTP filename from DOS
- Spring in Action 3 - passing parameters to advice
- Passing multiple POST parameters to Web API Controller Methods
- 大话数据结构之二:算法
- “开源”是什么,能吃吗?
- a different object with the same identifier value was already associated with the session。
- 笔记:Vmware安装提示The MSI failed
- File各种类操作文件、文件夹
- Passing …(rest) parameters between functions
- JQuery实现iframe自适应高度
- 自考*时间管理*压力
- Objective-C的self.用法的一些总结
- UIScrollView 原理详解
- fedora16 Samba配置
- ARM知识扫盲——JLINK与JTAG的区别
- C++条件编译
- 过载保护