当前位置:网站首页>Detailed explanation of ES6 deconstruction grammar

Detailed explanation of ES6 deconstruction grammar

2022-07-01 03:21:00 Brave Xiao Chen

        ES6 The deconstruction syntax of simplifies the complex value taking process in our development process , May you in a.b.c.d Others have already taken out the value from the beginning , Make the code more concise . Now let's start to explain the grammar in detail .

One 、 Monolayer deconstruction

Monolayer deconstruction

const earth = {
  people: ' human beings ',
  animal: ' animal '
}
const { people, animal } = earth
console.log(people, animal);// human beings   animal 

Single layer deconstructs and changes the variable name

const earth = {
  people: ' human beings ',
  animal: ' animal '
}
const { people: ren, animal } = earth
console.log(ren, animal);// human beings   animal 

Two 、 Multi level deconstruction

Multi level data deconstruction

const earth = {
  people: {
    male:' male ',
    female:' Woman '
  },
  animal: ' animal '
}
const {people:{male,female}}=earth
console.log(male,female);

Multi level deconstruction and change variable names

const earth = {
  people: {
    male:' male ',
    female:' Woman '
  },
  animal: ' animal '
}
const {people:{male:man,female}}=earth
console.log(man,female);

2022.06.29

原网站

版权声明
本文为[Brave Xiao Chen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010308021054.html