JavaScript classes in an application with Cordova

-2

When I try to declare a class in JavaScript, using, for example:

class musica{ 
    contructor(){ 
      this.variavel = 3;
    } 
    funcao(){
      console.log('essa é a minha variável: '+ this.variavel);
    }
}

In my application I get the following error:

  

Uncaught SyntaxError: unknown message reserved_word

Can not create classes in JS using Cordova?

    
asked by anonymous 23.03.2018 / 04:07

1 answer

0

Cordova does not support ES6, classes, the way you did, are only available from it. Understand that many technologies are still experimental and not fully implemented.

Ionic with Cordova uses classes, but in fact it is not JavaScript and rather TypeScript that in build is "compiled" (recoded) for JavaScript.

You may find some articles out there that say that it is possible to use ES6 in Cordova, but in fact these articles are talking about the Babel project :

What is a 'compiler' that turns your script like ES6 into 'ES5', that is, allows you to use ES6 before it's available.

    
23.03.2018 / 23:14