DEV Community

Discussion on: Future Javascript: Records and Tuples

Collapse
 
rajeshdixitsatyanarayan profile image
Rajesh Dixit

This looks great but I wonder the reasoning behind this. We can still achieve this using Object.freeze, so what is the benefit? Only thing I can see is compare by value but that does not seem that big of a reason to create new datatypes in a language. One thing I can think would help though is using Set/ Map with these. You can store complex record and to fetch it, all you need is set.get(#{...}).

Collapse
 
amymc profile image
amy mccarthy • Edited

Object.freeze isn't deeply immutable. From the MDN docs:

"The result of calling Object.freeze(object) only applies to the immediate properties of object itself and will prevent future property addition, removal or value re-assignment operations only on object. If the value of those properties are objects themselves, those objects are not frozen and may be the target of property addition, removal or value re-assignment operations."