1、对象解构是为了简化对象属性取值
解构没有顺序,但要和对象属性名称保持一致,如下:
<script>
const user = {
username:'张三',
age:28,
getUsername(){
return this.username;
}
}
console.log(user.username);
console.log(user.age);
console.log(user.getUsername());
let {username,age} = user;
console.log(age);
</script>
2、解构也可以定义到对象的函数方法中
<script>
let { abs,random } = Math;
console.log(abs(-1));
console.log(random());
</script>