未使用解构

    1. const user = {
    2. name: "kevin",
    3. age: 11,
    4. sex: "男",
    5. address: {
    6. province: "四川",
    7. city: "成都"
    8. }
    9. }
    10. function print(user) {
    11. console.log(`姓名:${user.name}`)
    12. console.log(`年龄:${user.age}`)
    13. console.log(`性别:${user.sex}`)
    14. console.log(`身份:${user.address.province}`)
    15. console.log(`城市:${user.address.city}`)
    16. }
    17. print(user)

    解构参数

    1. function print({ name, age, sex, address: {
    2. province,
    3. city
    4. } }) {
    5. console.log(`姓名:${name}`)
    6. console.log(`年龄:${age}`)
    7. console.log(`性别:${sex}`)
    8. console.log(`身份:${province}`)
    9. console.log(`城市:${city}`)
    10. }
    11. const user = {
    12. name: "kevin",
    13. age: 11,
    14. sex: "男",
    15. address: {
    16. province: "四川",
    17. city: "成都"
    18. }
    19. }
    20. print(user)