BABEL_PARSE_ERROR error using ES6 array

Asked

Viewed 41 times

-1

Hello! I am new using ES6, I did the installation of Babel, so when using array the Bundle accuses BABEL_PARSE_ERROR. It appears like this: Syntaxerror: C: xampp htdocs ES6 main.js: Unexpected token (3:20)

The code I’m using is as follows::

class todoList{
    constructor(){
        this.todos[];
    }

    addTodo(){
        this.todos.push("Novo todo");
        console.log(this.todos);
    }

}

const MinhaLista = new todoList();    

document.getElementById('novotodo').onclick = function(){
    MinhaLista.addTodo();
}

The error is precisely in the array inside the constructor: constructor(){ this all.[]; }

Can anyone tell me if there are any updates that have modified this, or if I’m doing something wrong?

1 answer

0


All assigning values to variables in Javascript is done using an equal sign. Whether they are strings, integers... or arrays.

Only the same signal was missing in the code in question.

constructor() {
   this.todos = [];
}
  • Really, I was missing the equal sign between everyone and []. Thank you! Lack of attention my xD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.