ECMA proposal would bring records and tuples to Java Script

JavaScript would gain record and tuple value types under a before ECMA International, the standards body that oversees the popular programming language for web development.

and tuples would introduce two deeply immutable data structures to JavaScript: Record, an object-like structure, and Tuple, an array-like structure. A draft of the plan with ECMA Technical Committee 39, which governs ECMAScript, the standard underlying JavaScript.

and tuples, the 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.

JavaScript engines might perform certain optimizations on construction, manipulation, and comparison of records and tuples, analogous to how strings are implemented. Records and tuples are intended to be usable and understood with external type system supersets such as TypeScript or Flow.

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 userland 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 Record and 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 BigInt type.

You might also like

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More