博客列表 >11.3日作业

11.3日作业

子墨吖ฅฅ
子墨吖ฅฅ原创
2022年11月04日 00:15:17315浏览
  1. // 数组的解构
  2. let [uname, email] = ['杨过', '123@qq.com']
  3. console.log(uname, email)
  4. ;[uname,...arrs] = ['小龙女', '123@qq.com' , '女']
  5. console.log(uname,...arrs)
  6. //对象的解构
  7. let show = (user) =>`${user.uname}: ( ${user.email} )`
  8. let user = { uname: '子墨', email: '3171275340@qq.com' }
  9. console.log(show(user));
  10. // 使用对象解构对上面代码进行重写
  11. show = ({username,email}) => `${username}: ( ${email} )`
  12. user = { username: '子墨', email: '123456@qq.com' }
  13. console.log(show(user));
  14. // 访问器属性
  15. const obj = {
  16. lesson: {
  17. name: '子墨',
  18. sex:'男',
  19. },
  20. get sex() {
  21. return {
  22. name: this.lesson.name,
  23. sex: this.lesson.sex,
  24. }
  25. },
  26. set sex(value){
  27. if(value === "男" || value === "女"){
  28. this.lesson.sex = value
  29. }else{
  30. console.log("性别必须是男或女")
  31. }
  32. }
  33. }
  34. console.log(obj.sex)
  35. obj.sex = "000"
  36. console.log(obj.sex)

运行图

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议