spread operator in es6

发布时间:2019-08-09 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了spread operator in es6脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

根据mdn的解释 the sPRead syntax allows an exPresstion to be expanded in palces where mutiple arguments (for function calls)or multiple elements (for array lITerals) or multiple variables (for destrucring assignment) are exPEcted
1.在函数调用时用来展开数组到函数的参数

例子:

function add(a, b, c,d) {
    console.LOG(a + b + c+d)
}
VAR nums = [@H_406_30@34, 21, 2,2]
add(...nums)
//console output 49

2.展开数组到一个数组元素

var fruits=['apple','pea','cherry']
var foods=['rice',...fruits,'mellon','noddles']
console.log(foods)
//output in command line ['rice','apple','pea','cherry','mellon','noddles'] 

3.展开对象到一个对象内的属性(stage 3 draft ,has not been supported util right now)

let obj = {
    name: 'Ajaxyz',
    age: 25
}
let objClone = {
    gend: "male",
    ...obj
}
console.log(objClone)

脚本宝典总结

以上是脚本宝典为你收集整理的spread operator in es6全部内容,希望文章能够帮你解决spread operator in es6所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。