foreword
In the process of communicating with the master, I learned that there is a relatively magical operation in javascript-object deconstruction. I was stunned when I first saw the code and console, but after careful analysis, I got a preliminary understanding of the reasons. I hereby record it for easy reference and share it with everyone.
example one
var {
a} ={
a: 1,
b: 2
}
Results of the:
Example two
var {
a, d=1} ={
a: 1,
b: 2
}
Example three
var {
a, b:{c}, d} = {
a: 1,
b: {c: 1},
d: 2
}
//解构是按照相对路径去查找源对象。在对象中b的值其实是一个对象{c:1},这对应了父对象的b:{c},所以会输出c=1
Example four
var {
a, b, b:{c}, d} = {
a: 1,
b: {c: 1},
d: 2
}