What is “accessor function”?

后端 未结 3 1706
春和景丽
春和景丽 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 21:44

    "A pair of accessor functions" are the getter and the setter.

    Documentation and example:

    var o = {}; // Creates a new object
    
    // Example of an object property added with defineProperty with an accessor property descriptor
    var bValue = 38;
    Object.defineProperty(o, 'b', {
      get: function() { return bValue; },
      set: function(newValue) { bValue = newValue; },
      enumerable: true,
      configurable: true
    });
    

提交回复
热议问题