Record, an object-like structure, and
Records and tuples, the proposal states, can only contain primitives and other records and tuples. They can be thought of as “compound primitives.”
And by being thoroughly based on primitives, they are deeply immutable. Like objects and arrays, records and tuples support comfortable idioms for construction, use, and manipulation, the proposal states. They are compared by contents rather than by identity.
Currently, userland libraries such as immutable.js implement similar concepts. A previous ECMA proposal for immutable data structures was attempted but abandoned because of complexity and lack of sufficient use cases, the proposal states.
The new proposal introduces significant changes, offering usability advantages over user-land libraries such as the following:
- Records and tuples are easily introspectable in a debugger
- No additional branching is needed to write a generic library that consumes immutable and JS objects
- Use cases are avoided where developers may expensively convert between regular JS objects and immutable structures
Records and tuples interoperate well with objects and arrays. They can be read the same way as objects and arrays. The key difference centers on deep immutability and comparison by value rather than identity. Also, the proposed syntax significantly improves the ergonomics of using
Tuple in code.
The most recent version of the ECMAScript specification, version 2020, was adopted in June. It featured capabilities in areas such as module loading and a new