What is the strange problem with prototype using a constructor of Object.defineProperty?

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

Feb.20,2022

Google tried to get the same result as yours, and then tested

console.dir(foo.hasOwnProperty('x'));

returns false, probably guessing that it is probably a problem in the form of console output. Using Firefox, the result is as follows

clipboard.png

foo.y = 3;

clipboard.png

y x ;

: ;
:

clipboard.png

Menu