箭头功能“期望的表达"是指箭头功能.语法错误 [英] Arrow function "expression expected" syntax error
问题描述
我要转换此代码:
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'));
我在箭头处收到expression expected
语法错误.我在此处的默认语法中进行了查找,似乎像我的代码的语法是正确的.任何想法可能是什么问题吗?
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?
我使用以下语法:
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.
在node v5.3.0
推荐答案
在编辑Node.js程序时,我遇到了 Webstorm 报告的错误expression expected
.在这种情况下,解决方案是将语言版本设置为支持此功能的版本.
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.
这篇关于箭头功能“期望的表达"是指箭头功能.语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!