The following javascript module add a simple div into html file. When I called board.drawIn(), everything works well. But when I called board.initIn(), I got,
gomoku.js:3 Uncaught TypeError: Cannot set properties of undefined (setting 'board')
I'm quite confused because initIn() function actually does nothing but call drawIn() directally. Anyone can help?
const board = (() => {
function drawIn(container) {
this.board = document.createElement('div');
this.board.classList.add('gomokuBoard');
container.appendChild(this.board);
}
function initIn(container) {
drawIn(container);
}
return { drawIn, initIn };
})();
const gomoku = (() => {
function initIn(container) {
//board.drawIn(container); /* this works */
board.initIn(container); /* doesn't work */
}
return { initIn };
})();
gomoku.initIn(document.querySelector('body'));
.gomokuBoard {
width: 100px;
height: 100px;
border: 1px solid black;
}