函数参数的解构赋值
1、函数参数的解构赋值
//函数参数的解构赋值 function swap([x,y]){ return [y,x]; }; let arr = [1,2]; arr = swap(arr);
2、对象的解构赋值
//对象的解构赋值 function Computer({ cpu, memory, software = ['ie6'], OS = 'windows 3.5' }){ console.log(cpu); console.log(memory); console.log(software); console.log(OS); }; new Computer({ memory:'128G', cpu:'80286', OS:'windows 10' })
3、小案例实现
//小案例实现 function getUserInfo({ name, sex = '女', age, height = '160cm' }){ console.log(name); console.log(sex); console.log(age); console.log(height); }; getUserInfo({ name:'小花', age:'23', height:'158cm' })