Getting an error saying
this.boardMatrix[i][j] = 1;
^
TypeError: Cannot set properties of undefined (setting '2')
When I already have a private method that initializes the matrix to zeros when the constructor is called. This is a simplified version of the class:
class gameBoard {
constructor() {
this.boardMatrix = this.#_initializeBoard;
}
#_initializeBoard() {
let board = [];
for (let i = 0; i < 10; i++) {
board.push([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
}
return board;
}
placeShip(i, j, axis) {
// some code
this.boardMatrix[i][j] = 1;
}
}
And here’s how I triggered the error:
console.log(gameboard.boardMatrix());