可预测
节省内存? — 需证明
易回溯
并发安全
函数式编程,无副作用
缺点:
- 增加资源文件大小?
易与mutable的原生对象混淆:
解决办法,
1. immutable object以$$开头命名
2. 使用Immutable.fromJS创建对象,而非Immutable.Map或Immutable.List等,以便于视觉上区分这两种对象.
[Immutable.is](http://immutable.is/)
比较的是两个对象的 hashCode 或 valueOf(对于 JavaScript 对象)。由于 immutable 内部使用了 Trie 数据结构来存储,只要两个对象的 hashCode 相等,值就是一样的。这样的算法避免了深度遍历比较,性能非常好。
后面会使用 [Immutable.is](http://immutable.is/)
来减少 React 重复渲染,提高性能。
structural sharing
Immutable.js comes from Facebook and is one of the most popular implementations of immutable data structures
http://stackoverflow.com/questions/34385243/why-is-immutability-so-importantor-needed-in-javascript