Search code examples
timerargumentsdelayhaxe

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


Solution

  • 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