Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Uncaught TypeError: Cannot set properties of undefined in Javascript module

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;
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!