Function setNonWritable

  • Sets the specified properties of an object to be non-writable.

    Parameters

    • object: Record<ObjectKey, any>

      The object whose properties are to be made non-writable.

    • Rest ...properties: string[]

      The names of the properties to be made non-writable.

    Returns void

    Throws

    Will throw an error if any of the specified properties do not exist on the object.

    Example

    const obj = { a: 1, b: 2, c: 3 };
    setNonWritable(obj, 'a', 'b');
    obj;;
    //=> { a: 1, b: 2, c: 3 }
    obj.a = 10;;
    //=> Throws an error
    obj.b = 20;;
    //=> Throws an error
    obj.c = 30;;
    //=> Works fine

Generated using TypeDoc