[英]Difference between Immutable.js List() and List.of()?
I'm reading through the Immutable.js docs for creating lists with List()
and List.of()
and I don't understand what the difference is. 我正在阅读Immutable.js文档,以使用
List()
和List.of()
创建列表,但我不知道有什么区别。 Any help with understanding this would be great. 理解这一点的任何帮助都将非常有用。
List.of()
uses each parameter as a separate element in the created list, while List()
takes a single parameter of some kind of iterable-like structure. List.of()
将每个参数用作创建的列表中的单独元素,而List()
采用某种类似于可迭代结构的单个参数。
Usage: 用法:
List.of("a", "b", "c"); // ["a","b","c"]
List(["a","b","c"]); // ["a","b","c"]
The ...
notation in the definition List.of<T>(...values: T[]): List<T>
is meant to indicate a variable number of arguments, which will be treated like an array internally, probably using the arguments
object or a rest parameter . 定义
List.of<T>(...values: T[]): List<T>
的...
符号用于指示可变数量的参数,这些参数在内部将被视为数组,可能使用arguments
对象或rest参数 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.