如何在Record中正确存储数组

时间:2017-01-30 19:02:14

标签: immutable.js

var z =记录({a:[]});

var a = new z({a: [1]});
var b = new z({a: [1]});
expect(Immutable.is(a, b)).to.be.true; // false

这会返回 false ,因为 [] 是一个可变结构。所以我已经将代码更改为:

var z = Record({a: List()});

var a = new z({a: List([1])});
var b = new z({a: List([1])});
expect(Immutable.is(a, b)).to.be.true; // true

它似乎有用,因为 Immutable.List 是不可变的。那么这是在Record中存储数组的正确方法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

`int A[] = new int[5];` //creates the "A" array with an integer datatype
`int B[] = new int[5];` //creates the "B" array with an integer datatype

将是正确的语法。您可以删除expect(Immutable.is(a, b)).to.be.true; // true

您可能收到错误,因为您在上面提供的语法中没有数据类型。

希望这有帮助。

相关问题