You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to add a new function _.deepFreeze to lodash.
Pure javascript Object.freeze() does not freeze nested object.
constuser={name: 'Taro',age: 24,email: 'foo@example.com',location: {country: 'Japan',city: 'Tokyo'}}Object.freeze(user);user.location.city='Kyoto';// This will work. Because nested objects are not frozen.console.log(user.location.city);//=> 'Kyoto'// Change from 'Tokyo' to 'Kyoto'
The _.deepFreeze function I want to propose also freezes nested objects.
constuser={name: 'Taro',age: 24,email: 'foo@example.com',location: {country: 'Japan',city: 'Tokyo'}}_.deepFreeze(user);user.location.city='Kyoto';// This will not work. user.location is immutable!// TypeErrors will occur here if in strict mode.console.log(user.location.city);//=> 'Tokyo'// Not changed
What do everyone think?
Thank you very much!
The text was updated successfully, but these errors were encountered:
I think something like this would be good on its own or in a suite of utils for immutability. For a reference implementation you can check out deep-freeze-strict.
Hi!
I want to add a new function
_.deepFreeze
to lodash.Pure javascript
Object.freeze()
does not freeze nested object.The
_.deepFreeze
function I want to propose also freezes nested objects.What do everyone think?
Thank you very much!
The text was updated successfully, but these errors were encountered: