我有一个函数传递一个数组到另一个函数作为参数,将有多个数据类型的数组,但我想知道如何在一个函数或引用传递给一个函数,所以其他的功能,可以把它随时
恩。
功能的:
添加(新的Array(你好,有的功能));
函数B:
公共函数b(参数:数组){
VAR MyString的=的args [0];
变种myFunc的=的args [1];
}
解决方案
简单函数名作为参数传递,没有,就像在AS2或JavaScript?
函数functionToPass()
{
}
功能otherFunction(F:功能)
{
//可以在这里传递函数
F();
}
otherFunction(functionToPass);
I have a function that passes an array to another function as an argument, there will be multiple data types in this array but I want to know how to pass a function or a reference to a function so the other function can call it at any time.
ex.
function A:
add(new Array("hello", some function));
function B:
public function b(args:Array) {
var myString = args[0];
var myFunc = args[1];
}
解决方案
Simply pass the function name as an argument, no, just like in AS2 or JavaScript?
function functionToPass()
{
}
function otherFunction( f:Function )
{
// passed-in function available here
f();
}
otherFunction( functionToPass );