Immutable.js它内部实现了一套完整的 Persistent Data Structure
fromJS()
将数组或者对象转换为Immutable
let map=Immutable.fromJS({ a:1, b:2 }); let list=Immutable.fromJS([ { a:1, b:2 } ]); console.log(map); console.log(list);
is()
检测是否相等,和Object.is()是有区别的
let map1=Immutable.Map({a:1}); let map2=Immutable.Map({a:1}); console.log(map1===map2); //false console.log(Object.is(map1,map2)); //false console.log(Immutable.is(map1,map2)); //true
List是个索引集合
List.isList() 判断是否为List集合
let list=Immutable.List([1,2,3]); console.log(Immutable.List.isList(list)); //true
List.of()创建一个集合
console.log(Immutable.List.of([1,2,3]));
List大小
let list=Immutable.List([1,2,3]); console.log(list.size); //3 console.log(list.count()); //3
获取List索引元素
console.log(list.get(0)); console.log(list.get(-1)); //反向索引