解构对象
const tom = {
name:'tom',
age:21,
height:170,
greet:function () {
return `hello ,I'm ${this.name}`
// console.log(`hello, I'm ${this.name}`)
// console.log(this)
}
}
tom.greet();
let { name, age} = tom
name ='jerry'
console.log(name, age)
解构传入的函数参数
const tom = {
name:'tom',
age:21,
height:170
}
// const printName = (people) => {console.log(`my name is ${people.name}`)};
const printName = ({name}) => {console.log(`my name is ${name}`)}
printName(tom);
解构数组
const arr = [1,2,3]
const [first] = arr
const [,second] = arr
const [,,third] = arr
console.log(first) //1
console.log(second) //2
console.log(third) //3