3 ms·
JS already supports immutable objects, by using Object.freeze().
by phailhaus 9y ago
JS already supports immutable objects, by using Object.freeze().
- spankalee 9y agoThat's not deeply immutable like you'd want for sharing objects across threads, or even for using in contexts like React and Redux.
- phailhaus 9y agoNot too hard to call Object.freeze() recursively to get the deep immutability you need. And of course there's ImmutableJS for other immutable data structures.
- bzbarsky 9y agoThat doesn't really make things immutable. Even ignoring the deep vs shallow issue, consider what effect Object.freeze has on a JS Map (hint: none, really; you can still add/remove things).
- phailhaus 9y agoRight, that's where libraries like ImmutableJS come in.