In the tc39 notes from 2021/01/25 there was discussion around the mutability of JSON modules. It was mentioned that projects could opt-in to immutability with:
you can simply be the first importer and then you can freeze the object
Deeply freezing an object is non trivial (though easier when source object is known to have come from JSON), so is commonly done by importing a library.
Question: Does anyone have any links to previous discussions about adding
Foreseen issues that have probably already come up:
- Would it handle cycles?
- Tracking cycles will consume more memory but avoids infinite loops
- Would it freeze prototypes?
- Should it visit just own properties?
- Should it freeze
Array.prototypewhen obj contains an array?
- Would it be configurable?
- It could take an argument similar to `JSON.stringify', an array of props to visit
- Preference for using
Recordfor deep immutability
EDIT: rephrased post as a question instead of an idea