function handleDeposit (accountNumber, amount) {
type: 'DEPOSIT',
accountNumber,
amount
}
在调用时返回undefined。我不确定es6在这里使用的是什么功能
等同于......
function handleDeposit (accountNumber, amount) {
return {
type: 'DEPOSIT',
accountNumber: accountNumber,
amount: amount
}
}
答案 0 :(得分:5)
您需要将对象结构中的属性包装为short hand properties作为给定ES5结果的ES6示例。
function handleDeposit (accountNumber, amount) {
return {
type: 'DEPOSIT',
accountNumber,
amount
};
}
您的代码
function handleDeposit (accountNumber, amount) { type: 'DEPOSIT', accountNumber, amount }
里面没有对象,但是标签type
,一些逗号运算符和结尾都没有返回任何值。
您可以使用undefined
获得函数的标准返回值。
答案 1 :(得分:4)
我不确定es6在这里使用的是什么功能
无。使用es2017预设通过Babel传递函数只会导致重新格式化代码。
这只是一个函数(带两个参数),包含一个label,后跟一个字符串文字,然后是两个参数,每个参数用comma operators分隔。
没有退货声明。
该功能不执行任何操作,不返回任何内容,并且是ES5。