ES6 结构赋值
es6结构赋值
具体点 解析结构,然后自动赋值,简化程序员代码编写;
我们搞个实例看看,平时主要用于对象解构,当然有时候也有数组的结构赋值;
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script type="text/javascript"> let obj={username:'java1234',age:31}; /*let username=obj.username; let age=obj.age;*/ let {username,age}=obj; console.info(username,age); let arr=[1,4,2,'ccc',false,'啦啦啦']; let [a,b,c,d,e,f]=arr; console.info(a,b,c,d,e,f) function func({username,age}){ // console.info(obj.username,obj.age); console.info(username,age); } func(obj); </script> </body> </html>