views:

50

answers:

3

Hi everyone,

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 creating any custom timer.

Thanks.

+1  A: 

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);
Cameron
+2  A: 

Use callback!

For example, if you want to call someFunction("abc"):

haxe.Timer.delay(callback(someFunction,"abc"), 10);
Andy Li
Cool, didn't know about that. Do you know when this was added to the language? (I haven't coded haXe in a while.)
Cameron
I have no idea, it has been there since I started using haXe(just some months ago).
Andy Li
It is in there since version 1.08 ;)
Franco Ponticelli
A: 

With someone's advice I got:

var self = this;
haxe.Timer.delay(function {self.someFunction("abc");}, 10); 

Any idea which one is the best?

Thank

Johnny Oin