• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

114
Views
Why are JavaScript functions from an imported class not defined using WebPack (Uncaught ReferenceError: function is not defined)

I am trying to call a function from an imported class in my index.js using WebPack like this:

import TetrisController from './js/Controller/tetrisController';

let tetris = new TetrisController();
tetris.runTetris();

TetrisController:

export class TetrisController {

    constructor() {
    ...
    }

    setuctxList() {
        let list = [];
        for (let i = 0; i < ucanvasList.length; i++) {
            uctxTemp = ucanvasList[i].getContext('2d');
            list.push(uctxTemp);
        }
        return list;
    }

    runTetris() {
        uctxList = setuctxList();
        addEvents(); // attach keydown and resize events

        function frame() {
            drawNext();
            requestAnimationFrame(frame);
        }

        reset();
        drawBottom();
        resize();
        frame();
    }

}

export default TetrisController;

The problem is that it returns a Uncaught ReferenceError which says the function setuctxList() is not defined.

The console error: main.js:2 Uncaught ReferenceError: setuctxList is not defined at Object.runTetris (main.js:2:71774)

I think it has something to do with WebPack but I do not know for sure. What is going wrong here?

9 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.