我只是想知道,是否有可能在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现在不应该被本地支持吗?
答案 0 :(得分:3)
我可以在没有Babel的情况下在Node.js中使用ES6 Javascript吗?
是的,您可以,Node支持ES2018之前的所有JS(ECMAScript)功能:https://node.green/
您应该这样创建方法:
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Recipients.Add Address ' <-- this is the line that is fixed.
.Recipients.ResolveAll
End With
无需仅出于持有匿名箭头功能的目的而创建属性。
答案 1 :(得分:0)
从Nodejs 11.11.0开始,类字段不是ECMAscript规范的一部分..但是..它们是第3阶段的提案
通过使用--harmony
命令行参数
看看当前的比赛状态,类字段似乎也不属于ES2019 (10th edition)
的一部分。虽然我找不到该文档(最多只能找到ES2018 (9th edition)
,但https://node.green/中的表在标题ESnext
的节中显示了类字段,该节位于ES2019
之后