[英]Javascript- Failed to execute 'observe' on 'MutationObserver'
I'm trying to create a tic tac toe game in javascript.我正在尝试在 javascript 中创建井字游戏。 I seem to be getting an error saying: Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': The options object must set at least one of 'attributes', 'characterData', or 'childList' to true..我似乎收到一条错误消息:未捕获的类型错误:无法在“MutationObserver”上执行“观察”:object 选项必须将“属性”、“字符数据”或“子列表”中的至少一个设置为真。
It is on this line:它在这条线上:
board.positions.forEach((el) => observer.observe(el,config));
It is on the function at the start of the game:游戏开始时在 function 上:
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();
}
I've tried to look up the error but can't find anything similar to it.我试图查找错误,但找不到类似的东西。
Try childList
instead of childlist
in your config.在您的配置中尝试使用childList
而不是childlist
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.