I'm trying to do a recursive loop but I'm facing some issues. I have issues with the 'this'.
I first started without the if statement, I had issues with the recursive call so I binded the this.play then it worked.
But, since I wanted to had a pause I added the if statement and now everything is broken.
I'm open to solutions, thank you :)
class Game {
constructor() {
this.turn = 0;
this.play = this.play.bind(this);
}
play(state) {
if (state) {
this.turn ++;
console.log(this.turn);
setTimeout(this.play, 2000);
} else {
console.log(this.turn);
}
}
}