наблюдаемый HQ. что плохого - PullRequest
0 голосов
/ 17 января 2020

У меня следующий код, и я получаю неожиданное предупреждение о строке. может кто-нибудь помочь. Эта же программа отлично работает на консоли.

class MyArray {
  constructor() {
    this.length = 0;
    this.data = {};
  }
  get(index) {
    return this.data[index];
  }
  push(item) {
    this.data[this.length] = item;
    this.length++;
    console.log(this.length);
  }
  pop() {
    const lastItem = this.data[this.length - 1];
    delete this.data[this.length - 1];
    this.length--;
    return lastItem;
  }
}

const newArr = new MyArray();
newArr.push('h1');
newArr.push('you');

Я получаю ошибку в const newArr = new MyArray() как «SyntaxError: Неожиданный токен». Почему это происходит?

...