一、基本概念
为什么需要解构呢,先来看一个例子
const student = {
name: 'ZhangSan',
age: 18,
scores: {
math: 19,
english: 85,
chinese: 100,
},
}
function displayInfo(student) {
console.log('name:', student.name)
console.log('math:', student.scores.math)
console.log('english:', student.scores.english)
console.log('chinese:', student.scores.chinese)
}
displayInfo(student)
大约 6 分钟