@pengzhanbo/utils - v3.7.3
    Preparing search index...

    Function deepFreeze

    • Deeply freeze an object recursively — the object and all its nested objects become immutable. Supports arrays, plain objects, Symbol keys, and non-enumerable properties.

      递归深度冻结一个对象 —— 对象及其所有嵌套对象变得不可变。 支持数组、普通对象、Symbol 键和不可枚举属性。

      Type Parameters

      • T

        The type of elements in the array / 数组元素的类型

      Parameters

      • obj: T

        The object to deeply freeze. 要深度冻结的对象。

      Returns T

      The same object, now deeply frozen. 同一对象,现已深度冻结。

      Mutation: This function mutates the original object in place via Object.freeze(). It does NOT create a copy. If you need a frozen copy, call deepClone first.

      Circular references: Handled safely via an internal Set that tracks visited objects, preventing infinite recursion.

      Supported types: Only arrays and plain objects (including their Symbol-keyed and non-enumerable properties) are recursively frozen. Other object types (Date, Map, Set, etc.) are left untouched.

      变更:此函数通过 Object.freeze() 原地修改原始对象,不会创建副本。 如需冻结副本,请先调用 deepClone

      循环引用:通过内部 Set 跟踪已访问对象来安全处理,防止无限递归。

      支持的类型:仅递归冻结数组和普通对象(包括其 Symbol 键和不可枚举属性)。 其他对象类型(Date、Map、Set 等)不受影响。

      const obj = deepFreeze({ a: { b: 1 }, c: [1, 2, 3] })
      // All nested objects are now immutable
      // obj.a.b = 2 // TypeError in strict mode

      Circular reference safety:

      const obj: any = { a: 1 }
      obj.self = obj
      deepFreeze(obj) // Does not cause stack overflow