Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:完成的很好,
// 数组的解构
let [uname, email] = ['杨过', '123456@qq.com']
console.log(uname, email)
;[uname,...arrs] = ['小龙女', '123456@qq.com' , '女']
console.log(uname,...arrs)
console.log('---------------------------------------')
//对象的解构
let show = (user) =>`${user.uname}: ( ${user.email} )`
let user = { uname: '盖伦', email: '123456@qq.com' }
console.log(show(user));
console.log('---------------------------------------')
// 使用对象解构对上面代码进行重写
show = ({username,email}) => `${username}: ( ${email} )`
user = { username: '盖伦', email: '123456@qq.com' }
console.log(show(user));
console.log('---------------------------------------')
// 访问器属性
const obj = {
lesson: {
name: '盖伦',
sex:'男',
},
get sex() {
return {
name: this.lesson.name,
sex: this.lesson.sex,
}
},
set sex(value){
if(value === "男" || value === "女"){
this.lesson.sex = value
}else{
console.log("性别必须是男或女")
}
}
}
console.log(obj.sex)
obj.sex = "000"
console.log(obj.sex)