Trying to use the Class keyword and modules in es6

I found this code in a book:

class Animal(){
    constructor(){
        this.legs = 4;
        this.eyes = 2;
        this.say = "Huh?"
     }
     speak(){
         console.log(this.say)
     }
}

The above should be the correct way to define a class, but I cannot use it in FF or chrome. I gotSyntaxError: class is a reserved identifier

I also played with modules. I put

export let hello = "hello from the first module" in firstModule.js file

than i put

import {hello} from "firstModule"
console.log(hello)

in the main.js file

and I put <script type="text/javascript" src="main.js"></script>in the index file and I gotSyntaxError: modules are not implemented yet

I assume that I have problems with es6 syntax that I thought I could, especially if I use babeljs

I hope you could see in this "try" link the link I tried to use the class operator, but I got an error Unexpected token (1:15).

How to use es6 material? I thought Babel should have switched es6 to es5. what am I doing wrong?

I also put <script type="application/javascript;version=1.7">in html file

+4
1

class Animal class Animal().
ES6 , , , , babel ES5. ,

<script type="text/babel" src="main.js"></script>

, babel-node, js webpack .

+1

Source: https://habr.com/ru/post/1598146/


All Articles