javascript - The object has attributes with set and get methods set in the prototype chain. This attribute will also be automatically written into the object.
世界只因有你
世界只因有你 2017-06-28 09:26:57
0
1
867

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?

世界只因有你
世界只因有你

reply all(1)
学霸

Seeing is not necessarily believing...

If you don’t believe me, try executing Object.getOwnPropertyDescriptor(o, 'a') and Object.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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template