集合操作在做什么?

What is set operation is doing?

从下面的例子来看,我显然做错了什么。

我正在尝试将 node2.data(在新树中)更新为等于 9。但是结果是 node1.data===9 (在新树中)并且缺少 node1.next 的内容。

为什么?

const node2 = {data: 2, next: []};
const node1 = {data: 1, next: [node2]};

const head1 = Immutable.fromJS(node1);
const head2 = head1.get('next').get(0).set('data', 9);
console.log(head2.get('data')); // 9
console.log(head2.get('next').get(0)); // undefined
// expected output: 1 and {.... object ...}!==undefined
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/4.0.0-rc.12/immutable.js"></script>

尝试 setIn:

const head2 = Immutable.setIn(head1, ['next', 0, 'data'], 9)