剩余参数
用于声明不确定参数数量的函数
function sum (first, ...args) { console.log(first); // 10 console.log(args); // [20, 30] } sum(10, 20, 30)
箭头函数也可以用
const sum = (...args) => { let total = 0; args.forEach(item => total += item); return total; }; console.log(sum(10, 20));//30 console.log(sum(10, 20, 30));//60
可以跟解构一起用
let students = ['wangwu', 'zhangsan', 'lisi']; let [s1, ...s2] = students; console.log(s1); // 'wangwu' console.log(s2); // ['zhangsan', 'lisi']
对象值省略
如果对象的属性名和值的变量名一样,可以省略值。
let User = '老王'; let obj = { //User: User User }
标签:剩余,ES6,省略,log,sum,args,20,let,console From: https://www.cnblogs.com/luyShare/p/17533043.html