I was just wondering, if it's possible to use ES6 in Node 10.15 now in 2019, because I thought, ES6 would now be a natively supported and implemented Javascript feature? I found some answer here: NodeJS plans to support import/export es6 (es2015) modules but I wasnt sure what the actual status is now.
I just tried out some ES6 classes with arrow functions in Node:
class Test {
testVar = 1;
constructor(x,y) {
this.counter =0;
this.x = x;
this.y = y;
this.increaseCounter();
this.testVar +=1;
}
getCounter = () => {
console.log("Counter:", this.counter);
}
increaseCounter = () => {
this.counter += 1;
}
}
I get an error:
getCounter = () => {
^
SyntaxError: Unexpected token =
and also, I cannot create class instance variables that are global to the class (and increase testVar by 1 every time a new class instance is created..) How is that normally done in Javascript classes?
I know there is a babel compiler package out there that supports this and transpiles the code somehow, but should ES6 not be natively supported Javascript code by now?