Skip to content
Advertisement

Tag: module-pattern

toggling variable inside Module Pattern using function declaration vs function expression

I have a module pattern with a variable setting the currentPlayer to 1. I use a function expression to toggle that variable If I run game.currentPlayer it logs 1, I then run game.toggleCurrentPlayer(), and it doesn’t change currentPlayer as intended, it still returns 1. However, changing the toggleCurrentPlayer() function using this, seems to be able to change the variable successfully

Advertisement