慕尼黑6497638
2019-03-29 21:43
square.js:70 Uncaught TypeError: Cannot read property '0' of undefined
at Square3.Square.rotate (square.js:70)
at Game.rotate (game.js:89)
at HTMLDocument.document.onkeydown (local.js:23)
试理解执行顺序:
刷新页面:init()【game.js】>>cur = SquareFactory.prototype.make(2,2,)【game.js】>>s.rotate(2)【squareFactory.js】>>rotate(num)【square.js】;
按上箭头键 : Game.rotate()【local.js】>>cur.rotate()【game.js】>>rotate(num)【square.js】;
疑惑:最后执行旋转到底有没有参数,假如有参数是哪一步赋值的?
楼下为我写的代码:
Square.prototype.canRotate = function (isValid) { var tsPoints = this.orgPoints; var tsCodes; var tsDrt = (this.drt + 1) % 4; tsCodes = [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ]; for (var i = 0; i < this.squCodes.length; i++) { for (var j = 0; j < this.squCodes[0].length; j++) { tsCodes[i][j] = this.rotCodes[tsDrt][i][j]; } } return isValid(tsPoints, tsCodes); }; Square.prototype.rotate = function (num) { if (!num) { mum = 1; } this.drt = (this.drt + num) % 4; for (var i = 0; i < this.squCodes.length; i++) { for (var j = 0; j < this.squCodes[0].length; j++) { this.squCodes[i][j] = this.rotCodes[this.drt][i][j]; } } };
基于websocket的火拼俄罗斯(单机版)
31676 学习 · 106 问题
相似问题