Tweakr
    Preparing search index...

    Function deepFreeze

    • Recursively freezes an object and all of its nested properties.

      This function ensures that an object, including all nested objects, cannot be modified. It safely handles circular references using a WeakSet.

      Type Parameters

      • T

        The type of the object to freeze.

      Parameters

      • obj: T

        The object to deeply freeze.

      • seen: WeakSet<WeakKey> = ...

        A WeakSet used internally to track already frozen objects to prevent infinite recursion (usually not set by the caller).

      Returns T

      The same object obj, now deeply frozen.

      1.1.0

      const obj = { a: 1, b: { c: 2 } };
      const frozenObj = deepFreeze(obj);

      frozenObj.a = 10; // No effect in strict mode
      frozenObj.b.c = 20; // No effect in strict mode