Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 此代码的es5等价物是什么_Javascript_Ecmascript 6_Ecmascript 5 - Fatal编程技术网

Javascript 此代码的es5等价物是什么

Javascript 此代码的es5等价物是什么,javascript,ecmascript-6,ecmascript-5,Javascript,Ecmascript 6,Ecmascript 5,它在被调用时返回undefined。我不确定这里使用的是es6的什么功能 它相当于 function handleDeposit (accountNumber, amount) { type: 'DEPOSIT', accountNumber, amount } 对于给定的ES5结果,您需要使用ES6示例将属性包装到对象结构中 function handleDeposit (accountNumber, amount) { return { type: 'DEPOSIT

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

它相当于

function handleDeposit (accountNumber, amount) {
  type: 'DEPOSIT',
  accountNumber,
  amount
}

对于给定的ES5结果,您需要使用ES6示例将属性包装到对象结构中

function handleDeposit (accountNumber, amount) {
  return {
    type: 'DEPOSIT',
    accountNumber: accountNumber,
    amount: amount
  }
}   
您给定的代码

内部没有对象,但有一个标签
类型
,一些逗号运算符,结尾不返回任何值

您可以获得
未定义
函数的标准返回值

我不确定这里使用的是es6的什么功能

没有。通过带有es2017预设的Babel传递函数只会重新格式化代码

这只是一个函数(包含两个参数),其中包含一个,后跟一个字符串文字,然后是两个参数,每个参数之间用分隔符分隔

没有返回语句


该函数不执行任何操作,不返回任何内容,并且是ES5。

!这看起来更像是一个语法错误,而不是使用任何ES6功能。const handleDeposit=(accountNumber,amount)=>({type:'DEPOSIT',accountNumber,amount}),但逗号运算符计算其每个操作数(从左到右)并返回最后一个操作数的值。。。那么,为什么该方法返回undefined而不是amount?@Robiningh,如果不返回
return
,则只返回
undefined
,而不返回逗号运算符和它的最后一个值。@Robiningh-逗号运算符导致语句
“存款”,accountNumber,amount
get将其计算为
amount
,但函数不返回它。
function handleDeposit (accountNumber, amount) {
    return {
        type: 'DEPOSIT',
        accountNumber,
        amount
    };
}
function handleDeposit (accountNumber, amount) {
     type: 'DEPOSIT',
     accountNumber,
     amount
}