What is “accessor function”?

后端 未结 3 1715
春和景丽
春和景丽 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条回答
  •  萌比男神i
    2021-01-23 21:56

    An accessor property is one that is defined in terms of getters and setters, not as a stored value that might be written to. The "pair of accessor functions" denotes the getter and the setter function.

    More information on this can be found in section §8.6:

    An Object is a collection of properties. Each property is either a named data property, a named accessor property, or an internal property:

    • A named data property associates a name with an ECMAScript language value and a set of Boolean attributes.
    • A named accessor property associates a name with one or two accessor functions, and a set of Boolean attributes. The accessor functions are used to store or retrieve an ECMAScript language value that is associated with the property.
    • An internal property has no name and is not directly accessible via ECMAScript language operators. Internal properties exist purely for specification purposes.

    and Section § 8.6.1:

    A named accessor property associates a name with the attributes listed in the following table:

    Attribute| Value     | Description
     Name    |  Domain   |
    ---------+-----------|---------------------------------------------------------
    [[Get]]  | Object or | If the value is an Object it must be a function Object.
             | Undefined | The function’s [[Call]] internal method (8.6.2) is
             |           | called with an empty arguments list to return the
             |           | property value each time a get access of the property is 
             |           | performed.
             |           |
    [[Set]]  | Object or | If the value is an Object it must be a function Object.
             | Undefined | The function’s [[Call]] internal method (8.6.2) is
             |           | called with an arguments list containing the assigned
             |           | value as its sole argument each time a set access of the
             |           | property is performed. The effect of a property's
             |           | [[Set]] internal method may, but is not required to,
             |           | have an effect on the value returned by subsequent calls
             |           | to the property's [[Get]] internal method.
             |           |
    [[Enume- | Boolean   | If true, the property is to be enumerated by a for-in
     rable]] |           | enumeration (see 12.6.4). Otherwise, the property is
             |           | said to be non-enumerable.
             |           |
    [[Confi- | Boolean   | If false, attempts to delete the property, change the
    gurable]]|           | property to be a data property, or change its attributes
             |           | will fail.
    

提交回复
热议问题