时间:2022/01/11
对象解构及对象传播操作符的示例代码:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>Document</title> 8 </head> 9 <body> 10 11 <script> 12 13 let info2 = { 14 title:"北邮", 15 name:"马驰", 16 go(){ 17 console.log("去上学"); 18 } 19 } 20 21 //对象解构及对象传播操作符 22 let {title, name, ...info3} = info2; 23 24 //打印结果 25 console.log(title); 26 console.log(name); 27 console.log(info3); 28 </script> 29 30 </body> 31 </html>
通过对象传递操作符,会将解构剩下的变量赋值给新定义的对象。