作者cjcat2266 (CJ Cat)
看板Flash
标题Re: [问题] 呼叫大量且命名有规律的function
时间Thu Sep 2 23:58:19 2010
※ 引述《Angelliya (不知...)》之铭言:
: var functionArray:Array = new Array(a1,a2,a3);
: function a1(xx) { trace(xx); }
: function a2(xx) { trace(xx); }
: function a3(xx) { trace(xx); }
如果a1, a2, a3名称不重要的话
其实可以用anonymous function来宣告唷 :)
var functionArray:Array =
[
function(xx:*) { trace(xx); },
function(xx:*) { trace(xx); },
function(xx:*) { trace(xx); }
];
//可以用这招把functionArray.length用一行code就复制到一个变数len中
//每次跑回圈就不用重新呼叫functionArray.length这个getter,以节省运算量
for (var i:int = 0, len:int = functionArray.length; i < len; ++i) {
functionArray[i]("hello");
}
--
CJ Cat = Croa'J Cat = Cockroach Cat = 西街凯特 = 蜚蠊猫 = 蟑螂猫
Blog
http://cjcat.blogspot.com
Gallery
http://cjcat2266.deviantart.com
ptt2 Board CJWorkshop - 阿多比闪光(Adobe Flash)研讨区
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.45.163.84
1F:推 etrexetrex:大神您回来啦 09/03 00:00