I want to transform this code:
我想要转换这段代码:
var formatQuoteAmount = function (tx) {
return Currency.toSmallestSubunit(tx.usd, 'USD');
};
var quoteAmounts = res.transactions.map(formatQuoteAmount);
into an anonymous arrow function. I've written this:
变成一个匿名箭头函数。我写这个:
var quoteAmounts = res.transactions.map(tx => Currency.toSmallestSubunit(tx.usd, 'USD'));
I get expression expected
syntax error at the arrow. I looked up the default syntax here and seems like the syntax of my code is correct. Any ideas what the problem might be?
我在箭头处得到表达式期望语法错误。我在这里查找了默认语法,看起来我代码的语法是正确的。有什么问题吗?
I have it working with this syntax:
我让它使用这种语法:
var quoteAmounts = res.transactions.map(function (tx) {
return Currency.toSmallestSubunit(tx.usd, 'USD')
});
but I want to make it a one-liner, with an arrow-function.
但我想把它做成一行,带有箭头函数。
Running on node v5.3.0
运行在节点v5.3.0
3 个解决方案
#1
#2
12
The following is what i did that work for me. (1) I change the JavaScript language option to ECMAScript 6 as show in the selected answer by @Joe23
以下是我为自己所做的。(1)将JavaScript语言选项改为ECMAScript 6,如@Joe23所示
(2) I close the Webstorm project/application.
(2)我关闭Webstorm项目/应用。
(3) Navigate to the project folder and delete the .idea folder in it. I believe this is the folder webstorm generated to keep information about the project/application.
(3)导航到项目文件夹,删除其中的.idea文件夹。我认为这是webstorm生成的文件夹,用来保存关于项目/应用程序的信息。
(4) I reopen my project in webstorm and the errors are gone.
我在webstorm重新打开我的项目,错误就消失了。
#3
0
Your syntax is correct and Nodejs supports arrow functions, but you it's not enabled by default.
语法是正确的,Nodejs支持箭头函数,但默认情况下不启用。
You should add the "--harmony" flag when you start the node process to enable it.
在启动节点进程以启用它时,应该添加“—harmony”标志。
#1
107
I had the error expression expected
reported by Webstorm when editing a Node.js program. In this case the solution is to set the language version to a version that supports this feature.
在编辑一个节点时,我得到了Webstorm所期望的错误表达式。js程序。在这种情况下,解决方案是将语言版本设置为支持该特性的版本。
#2
12
The following is what i did that work for me. (1) I change the JavaScript language option to ECMAScript 6 as show in the selected answer by @Joe23
以下是我为自己所做的。(1)将JavaScript语言选项改为ECMAScript 6,如@Joe23所示
(2) I close the Webstorm project/application.
(2)我关闭Webstorm项目/应用。
(3) Navigate to the project folder and delete the .idea folder in it. I believe this is the folder webstorm generated to keep information about the project/application.
(3)导航到项目文件夹,删除其中的.idea文件夹。我认为这是webstorm生成的文件夹,用来保存关于项目/应用程序的信息。
(4) I reopen my project in webstorm and the errors are gone.
我在webstorm重新打开我的项目,错误就消失了。
#3
0
Your syntax is correct and Nodejs supports arrow functions, but you it's not enabled by default.
语法是正确的,Nodejs支持箭头函数,但默认情况下不启用。
You should add the "--harmony" flag when you start the node process to enable it.
在启动节点进程以启用它时,应该添加“—harmony”标志。