为什么看不到数组?

时间:2019-05-14 07:39:32

标签: javascript arrays

我看了其他一些问题,但没有找到。

class Game {
  constructor() {
    this.positionX = 250;
    this.positionY = 250;
  }

  start() {
    this.appleX = this.appleY = 10; // apple position
    this.trail = [];
    this.tailSize = 5;
    this.speedX = this.speedY = 0;
    this.gridSize = this.tileCount = 25;
    ...
  }

  update() {
    ...
    if (this.trail.length == 0) { // this problem
      this.trail.prop.push({
        positionX: this.positionX,
        positionY: this.positionY
      })
    }

    while (this.trail.length > this.tailSize) { // this problem
      this.trail.shift();
    }
    ...
  }
}

const game = new Game();

错误:

  

无法读取未定义的属性“ length”

我已经描述了教室外面的阵列。

这一次我遇到了同样的问题。我该如何解决这个问题?

0 个答案:

没有答案