Blogger Information
Blog 18
fans 0
comment 0
visits 8453
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
对象与数组的解构赋值
时间在渗透
Original
375 people have browsed it
  1. // 数组的解构
  2. let [uname, email] = ['杨过', '123456@qq.com']
  3. console.log(uname, email)
  4. ;[uname,...arrs] = ['小龙女', '123456@qq.com' , '女']
  5. console.log(uname,...arrs)
  6. console.log('---------------------------------------')
  7. //对象的解构
  8. let show = (user) =>`${user.uname}: ( ${user.email} )`
  9. let user = { uname: '盖伦', email: '123456@qq.com' }
  10. console.log(show(user));
  11. console.log('---------------------------------------')
  12. // 使用对象解构对上面代码进行重写
  13. show = ({username,email}) => `${username}: ( ${email} )`
  14. user = { username: '盖伦', email: '123456@qq.com' }
  15. console.log(show(user));
  16. console.log('---------------------------------------')
  17. // 访问器属性
  18. const obj = {
  19. lesson: {
  20. name: '盖伦',
  21. sex:'男',
  22. },
  23. get sex() {
  24. return {
  25. name: this.lesson.name,
  26. sex: this.lesson.sex,
  27. }
  28. },
  29. set sex(value){
  30. if(value === "男" || value === "女"){
  31. this.lesson.sex = value
  32. }else{
  33. console.log("性别必须是男或女")
  34. }
  35. }
  36. }
  37. console.log(obj.sex)
  38. obj.sex = "000"
  39. console.log(obj.sex)

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的很好,
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!