What is “accessor function”?

后端 未结 3 1674
春和景丽
春和景丽 2021-01-23 21:34

In section 4.3.26 of the Standard ECMA-262 Edition:

Depending upon the form of the property the value may be represented either directly as a data value

3条回答
  •  盖世英雄少女心
    2021-01-23 22:00

    A pair of accessor function are referring to getter and setter. You can indirectly access some value in your object, for example:

    var person =
    {
        get Name()
        {
            return this.name;
        },
        set Name(value)
        {
            this.name = value;
        }
    };
    
    person.Name = "X";
    console.log(person.Name); // X
    

提交回复
热议问题