davidatthepark davidatthepark - 8 months ago 29
Javascript Question

Difference between Immutable.js List() and List.of()?

I'm reading through the Immutable.js docs for creating lists with

and I don't understand what the difference is. 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("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.