I have the following code
var tempGameState = JSON.parse(JSON.stringify(this.gameState))
tempGameState.forEach(function(row.bind(this), rowNum){
...
}));
when I put my console.log before the forEach loop like so:
var tempGameState = JSON.parse(JSON.stringify(this.gameState))
console.log(this.gameState)
tempGameState.forEach(function(row.bind(this), rowNum){
...
}));
I get my game state as the output
but when I put it inside the forEach loop like so:
var tempGameState = JSON.parse(JSON.stringify(this.gameState))
tempGameState.forEach(function(row.bind(this), rowNum){
console.log(this.gameState)
...
}));
I get undefined
.
I know this (ususally) has to do with scoping, but the javascript docs don't say anything about a new scope being created or how to handle this.