In this code, I add an action for a "bet", and pass its id as a parameter to a function. But when I call this arrow function later, the argument of this.undoBet equals to this.local_bets[this.local_bets.length].bet_id - the last bet_id that was passed inside the loop.
How to make it so that inside every arrow function, this.undoBet would preserve the bet_id assigned to it in that loop?
for (var k in this.local_bets) {
var bet = this.local_bets[k];
if (bet.status == BetStatus.accepted) {
// Here bet_id is correct for every "bet" variable
this.addUndo( "undo_bet", () => {
// When calling this later, bet_id equals to one that belongs to the last bet inside this.local_bets
this.undoBet( bet.bet_id );
});
}
}