开发者

Pass arguments to a delayed function with Haxe

Do you know if there is an easy way to pass some arguments to a function called via

haxe.Timer.delay(func, delay);

By "easy" I mean without creati开发者_JAVA百科ng any custom timer.


You can use bind() for this. For example, if you want to call someFunction("abc"):

haxe.Timer.delay(someFunction.bind("abc"), 1000); // 1s

Prior to Haxe 3, you could use callback:

haxe.Timer.delay(callback(someFunction,"abc"), 1000); // 1s


Everything can be achieved with an extra level of indirection :-)

It seems like you need a closure whose only job is to call the other function with arguments.

Something like this (untested):

haxe.Timer.delay(function () {
    func(arg1, arg2);
}, delay);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜