什么是此代码的es5等价物

rob*_*ngh -5 javascript ecmascript-5 ecmascript-6

function handleDeposit (accountNumber, amount) {
  type: 'DEPOSIT',
  accountNumber,
  amount
}
Run Code Online (Sandbox Code Playgroud)

它在调用时返回undefined.我不确定es6在这里使用的是什么功能

它等同于......

function handleDeposit (accountNumber, amount) {
  return {
    type: 'DEPOSIT',
    accountNumber: accountNumber,
    amount: amount
  }
}   
Run Code Online (Sandbox Code Playgroud)

Nin*_*olz 5

您需要将属性包装在具有短手属性的对象结构中,作为给定ES5结果的ES6示例.

function handleDeposit (accountNumber, amount) {
    return {
        type: 'DEPOSIT',
        accountNumber,
        amount
    };
}
Run Code Online (Sandbox Code Playgroud)

你给定的代码

function handleDeposit (accountNumber, amount) {
     type: 'DEPOSIT',
     accountNumber,
     amount
}
Run Code Online (Sandbox Code Playgroud)

里面没有对象,但是标签type,一些逗号运算符和结尾都没有返回任何值.

您将获得函数的标准返回值undefined.