El siguiente módulo de javascript agrega un div simple en un archivo html. Cuando llamé a board.drawIn() , todo funcionó bien. Pero cuando llamé a board.initIn() , obtuve,
gomoku.js:3 Uncaught TypeError: Cannot set properties of undefined (setting 'board') Estoy bastante confundido porque la función initIn() en realidad no hace nada más que llamar a drawIn() directamente. ¿Alguien puede ayudar?
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; }