0

I have a Typescript class called Game. This is the compiled JavaScript code:

import { Player } from './player.js';
export class Game {
    _currentPlayer = Player.X;
    start() {
        document.addEventListener('DOMContentLoaded', () => {
            document.body.addEventListener('click', this.markField);
        });
    }
    nextTurn() {
        this._currentPlayer = this.currentPlayer === Player.X ? Player.O : Player.X;
    }
    // Some code omitted
    isCompleted() {
        return false; // TODO
    }
    markField(event) {
        const button = event.target;
        if (!this.isCompleted() && button instanceof HTMLButtonElement) {
            button.setAttribute('aria-label', this.currentPlayer);
            button.setAttribute('disabled', 'disabled');
            this.nextTurn();
        }
    }
}

My main.js file initialises the game and calls game.start()

But when I click my buttons, the browser complains about this.isCompleted() not being a function; Uncaught TypeError: this.isCompleted is not a function

I edited the JavaScript output by removing the brackets for the isCompleted() function, but then my browser told me that this.nextTurn() is not a function as well.

k1r1ll
  • 1
  • 1

0 Answers0