Function prop

  • Type Parameters

    • T = unknown

    Parameters

    • context: T

      Object to define property

    • Optional field: PropertyKey

      Property name

      Optional
    • Optional value: unknown

      Property value

      Optional
    • mods: Mods = ''

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

    Returns ((field, value, mods?) => (field: PropertyKey, value: unknown, mods?: Mods) => ...)

      • (field, value, mods?): (field: PropertyKey, value: unknown, mods?: Mods) => ...
      • Parameters

        • field: PropertyKey
        • value: unknown
        • mods: Mods = ''

        Returns (field: PropertyKey, value: unknown, mods?: Mods) => ...

    Description

    Reduction for Object.defineProperty method for define properties

    Example

    import { define } from '@biorate/tools';

    const obj = {};

    define.prop(obj, 'test1', 1, 'cwe')
    ('test2', 2, 'c')
    ('test3', 3, '');

    console.log(obj); // { test1: 1 }
    console.log(Object.getOwnPropertyDescriptor(obj, 'test1')); // { value: 1, writable: true, enumerable: true, configurable: true }
    console.log(Object.getOwnPropertyDescriptor(obj, 'test2')); // { value: 2, writable: false, enumerable: false, configurable: true }
    console.log(Object.getOwnPropertyDescriptor(obj, 'test3')); // { value: 3, writable: false, enumerable: false, configurable: false }

Generated using TypeDoc