首页 > 解决方案 > Javascript - 得到一个未捕获的类型错误

问题描述

创建井字游戏,但由于某种原因,在执行observer.observe 时出现未捕获的类型错误。

这是发生错误的行:

board.positions.forEach((el) => observer.observe(el,config));

这是它发生的功能:

function TicTacToeGame() {
    const board = new Board();
    const humanPlayer = new HumanPlayer(board);
    const computerPlayer = new ComputerPlayer(board);
    let turn = 0;

    this.start = function () {
    const config = {childlist: true};
    const observer = new MutationObserver(()=> takeTurn());
    board.positions.forEach((el) => observer.observe(el,config));
   takeTurn();
    }

这个错误试图说什么以及解决它的最佳方法是什么。

编辑:这是我得到的错误:

Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.

标签: javascript

解决方案


推荐阅读