1: If the attributes of the set and get methods are set in the prototype chain of an object, the object will automatically write this attribute.
2: The code is as follows
let test = {
a:1,b:2
}
Object.defineProperty(test,'a',{
set(){
return 'set'
},
get(){
return 'get'
}
})
let o = {};
o.__proto__ = test;
3: View o
in the console
#4: Why does object o also have a property?
Seeing is not necessarily believing...
If you don’t believe me, try executing
Object.getOwnPropertyDescriptor(o, 'a')
andObject.getOwnPropertyDescriptor(test, 'a')
respectively.This should be just the effect created by Chrome's debugging tool to facilitate the display. This situation will not occur under Firefox.