utilitish - v0.0.10
    Preparing search index...

    Function defineIfNotExists

    • Defines a non-enumerable, non-writable, non-configurable property on a prototype if it does not already exist, or if the existing property is writable or configurable.

      • Intended for instance prototype methods (e.g., Array.prototype, String.prototype).
      • Does not overwrite non-configurable and non-writable properties.
      • Ensures immutability and hides the property from enumeration.

      Type Parameters

      • T extends object

        The prototype object type (e.g., Array.prototype).

      Parameters

      • prototype: T

        The prototype on which to define the method.

      • name: string

        The name of the method to define.

      • fn: Function

        The function to assign as the method.

      Returns void

      defineIfNotExists(Array.prototype, 'last', function() {
      return this[this.length - 1];
      });

      Use this function to safely add prototype methods without overwriting stable or built-in ones.