Function objDefineProp

  • Defines a new property directly on an object, or modifies an existing property on an object, and returns the object. This is a wrapper for Object.defineProperty

    This method allows a precise addition to or modification of a property on an object. Normal property addition through assignment creates properties which show up during property enumeration (for...in loop or objKeys method), whose values may be changed, and which may be deleted. This method allows these extra details to be changed from their defaults. By default, properties added using objDefineProp() are not writable, not enumerable, and not configurable.

    Property descriptors present in objects come in two main flavors: data descriptors and accessor descriptors. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter pair of functions. A descriptor must be one of these two flavors; it cannot be both.

    This is an alias for Object.defineProperty

    Type Parameters

    • T

    Parameters

    • target: T

      The object on which to define the property.

    • key: PropertyKey

      The name or Symbol of the property to be defined or modified.

    • descriptor: PropertyDescriptor & ThisType<any>

      The descriptor for the property being defined or modified.

    Returns T

    The object that was passed to the function with the new or updated property.