Javascript classes in an application with Cordova

Asked

Viewed 74 times

-1

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 have the following error:

Uncaught Syntaxerror: Unknown message reserved_word

Unable to create classes in JS using Cordova?

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 do not form fully implemented.

Ionic with Cordova uses classes, but in fact it is not Javascript but Typescript which, in the build is "compiled" (recoded) for Javascript.

You might find some articles out there that say you can use ES6 in Cordova, but actually these articles are talking about babel project:

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

Browser other questions tagged

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