我想知道在2019年现在的Node 10.15中是否可以使用ES6,因为我认为ES6现在应该是一种原生支持和实现的JavaScript功能。我在这里找到了一些答案:NodeJS plans to support import/export es6 (es2015) modules,但我不确定现在的实际状况。
我刚刚在Node中尝试使用了一些带箭头函数的ES6类:
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;
}
}
我遇到了一个错误:
getCounter = () => {
^
SyntaxError: Unexpected token =
同时,我无法创建类实例变量作为类的全局变量(并且每次创建新的类实例时将testVar增加1..)这在Javascript类中通常如何实现?
我知道有一个Babel编译器软件包支持此功能并以某种方式转换代码,但是ES6现在不应该被原生支持了吗?
--harmony
在节点中启用它。 - Jaromanda XTest.prototype
还是直接添加到类的每个实例中? - adigaES2015(第六版)
...它可能是ES2019(第十版)
或更高版本,因为它不在ES2018(第九版)
中 - ECMA并没有在2015年停止开发javascript...自那以后已经发布了3个以上的规范。 - Jaromanda X