utilitish - v0.0.10
    Preparing search index...

    Function defineStaticIfNotExists

    • Defines a static property on a constructor if it does not already exist, or if the existing property is writable or configurable.

      • Only affects static properties on constructors (e.g., Array, Map).
      • The property is created as non-enumerable, immutable, and non-configurable.
      • Does not overwrite existing properties that are non-configurable and non-writable.

      Type Parameters

      • T extends object

        The constructor type (e.g., typeof Array).

      Parameters

      • constructor: T

        The constructor object on which to define the static method.

      • name: string

        The name of the static method to define.

      • fn: Function

        The function to assign as the static method.

      Returns void

      defineStaticIfNotExists(Array, 'range', function(start: number, end?: number) {
      // implementation
      });

      To forcefully replace an existing property, delete it first or use Object.defineProperty directly.