Function objDefineGet

  • Try to define a get object property accessor for the target object, if a function is past as the value this will be assumed to be a getter function and NOT the value.

    Type Parameters

    • T
    • V = any

    Parameters

    • target: T

      The object on which to define the property.

    • key: PropertyKey

      The name of the property to be defined or modified

    • value: V | (() => V)

      The value or a function that returns the value

    • Optionalconfigurable: boolean

      Can the value be changed, defaults to true.

    • Optionalenumerable: boolean

      Should this get property be enumerable, defaults to true.

    Returns T

    The object that was passed to the function

    It is recommended that you use objDefine instead objDefineGet or objDefineAccessors as it provides a deterministic way for identifying whether the value is a value or a function rather than wrapping any function value in another function.