Just ran into this problem in Haxe and wondered if it was a mistake or if it was done on purpose ...
I bound a function that prints a timestamp. The timestamp in this case was a getter in my globals class. I expected that if I had to wait a few seconds and then call the associated function, it would use the getter value at the time the function was bound. That was not so. Instead, it seems to call a getter to get the current value each time.
I checked if this happened if I switched from using getter to a regular function call to get my timestamp as my parameter. The latter works as expected.
function printTime(time:Int):Void {
trace("The time is: " + time);
}
var p:Void->Void = printTime.bind(Globals.timestampgetter);
var p2:Void->Void = printTime.bind(Global.timestampfunc());
p();
p2();
EDIT:
Forgot to mention ... I am using Haxe 3.1.3 and OpenFL 3.0.0 beta, compiling for the purpose of Flash.
Esrix source
share