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.
The type of the object to freeze.
The object to deeply freeze.
A WeakSet used internally to track already frozen objects to prevent infinite recursion (usually not set by the caller).
The same object obj, now deeply frozen.
obj
1.1.0
const obj = { a: 1, b: { c: 2 } };const frozenObj = deepFreeze(obj);frozenObj.a = 10; // No effect in strict modefrozenObj.b.c = 20; // No effect in strict mode Copy
const obj = { a: 1, b: { c: 2 } };const frozenObj = deepFreeze(obj);frozenObj.a = 10; // No effect in strict modefrozenObj.b.c = 20; // No effect in strict mode
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.