Reputation: 9
I am trying to understand the revealing-module pattern but when try to update or access the variables falling into errors and can anyone provide an example how to update/access the variables in revealing-module pattern
I get
main.js:20 Uncaught ReferenceError: board is not defined at main.js:20
var module = (function() {
var publicVariable = "X";
var board = new Array(9).fill(null)
return {
//This function can access `publicVariable` !
changePlayer: function() {
return (publicVariable = publicVariable === "X" ? "O" : "X")
},
MakeMove: function(i) {
return (board[i] = publicVariable)
},
board: board
}
})();
module.MakeMove(2)
console.log(board[2])
Upvotes: -1
Views: 57
Reputation: 259
You are returning an object, so in order to access board
, you'd have to do console.log(module.board[2])
.
Upvotes: 1