Function accessor

  • Type Parameters

    • T = unknown

    Parameters

    • context: T

      Object to define property

    • Optional field: PropertyKey

      Property name

      Optional
    • Optional accessor: Accessor
      Optional
    • mods: Mods = ''

      Reduction for enumerable, configurable, writable - 'cwe' string, see Mods

    Returns ((field, accessor, mods?) => (field: PropertyKey, accessor: Accessor, mods?: Mods) => ...)

      • (field, accessor, mods?): (field: PropertyKey, accessor: Accessor, mods?: Mods) => ...
      • Parameters

        Returns (field: PropertyKey, accessor: Accessor, mods?: Mods) => ...

    Description

    Reduction for Object.defineProperty method for define accessors (getters and setters)

    Example

    import { define } from '@biorate/tools';
    const obj = {
    _value: 0,
    };

    define.accessor(
    obj,
    'value',
    {
    get() {
    return this._value;
    },

    set(value: number) {
    this._value = value;
    },
    },
    'cw',
    );

    console.log(obj); // { _value: 0 }
    console.log(Object.getOwnPropertyDescriptor(obj, 'value'));
    // {
    // get: [Function: get],
    // set: [Function: set],
    // enumerable: false,
    // configurable: true
    // }

Generated using TypeDoc