one day when I was reading defineProperty on MDN, there was a paragraph I didn"t understand, so I ran a piece of code like this on the browser to debug
var Foo = function(){};
Object.defineProperty(Foo.prototype,"x",{
get(){
return 3;
}
});
var foo = new Foo();
console.dir(foo);
the result I expect should be
Foo{
__proto__:{
constructor: (),
x: 3,
__proto__: Object
}
}
but the real result is
Foo{
x: 3,
__proto__:{
constructor: (),
x: 3,
__proto__: Object
}
}
Why does the x attribute already appear on the outermost layer? Ask the great god and the teacher to explain