I am trying to use closures in Typescript inside a loop, but I've got some serious problems:
for(let vehicle of vehicles) {
update(location =>
{
vehicle.location = location;
}
);
}
I am using Typescript 1.8.1 and I need to target ES5, when I compile the following error shows:
Loop contains block-scoped variable 'vehicle'
referenced by a function in the loop.
This is only supported in ECMAScript 6 or higher.
If i use var instead of let in the loop, it uses last value of vehicle for all closures.
Is there any good workaround for this problem when targeting ES5?