Menu
Proposal would bring records and tuples to JavaScript

Proposal would bring records and tuples to JavaScript

A technical committee has proposed adding new deeply immutable value types to the ECMAScript standard

Credit: Dreamstime

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

Records 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.

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.

JavaScript engines might perform certain optimisations 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 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 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.


Follow Us

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags javascript

Brand Post

Featured

Slideshows

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

Hundreds of leaders from the New Zealand IT industry gathered at the Hilton in Auckland on 17 November to celebrate the finest female talent in the Kiwi channel and recognise the winners of the Reseller News Women in ICT Awards (WIICTA) 2020.

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards
Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

The leading female front runners of the New Zealand ICT industry joined together for the annual Reseller News Women in ICT Awards event at the Hilton in Auckland, during which hundreds of guests celebrated 13 outstanding individuals who won awards, chosen from more than 50 finalists representing over 30 organisations.

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards
Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

More than 500 channel leaders gathered in Auckland on 21 October at the ​Reseller News Innovation Awards ​2020 to celebrate the achievements of the New Zealand technology industry's top partners, start-ups, vendors, distributors and individuals.

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners
Show Comments