ECMAScript 2022 endorses class fields, top-level await Otesanya David March 24, 2022

ECMAScript 2022 endorses class fields, top-level await

ECMAScript 2022 endorses class fields, top-level await

[ad_1]

ECMAScript, the official standard behind JavaScript, is set to be formally fitted with capabilities ranging from class fields to ergonomic brand checks and a top-level await capability.

The ECMAScript 2022 specification is due to be approved by ECMA International in June. But the features already are available in most browsers, said Robert Palmer, co-chair of the TC39 committee that shepherds the standard. Feature availability in JavaScript engines is more relevant to developers than appearance in the actual specification, Palmer said.

ECMAScript 2022 features eight finished proposals:

  • Class field declarations for JavaScript, providing an orthogonally informed combination of public and private fields proposals.
  • Ergonomic brand checks for private fields, providing brand checks without exceptions.
  • Top-level await, which enables modules to act as big async functions. With top-level await, ECMAScript modules can await code resources, causing other modules that import them to wait before starting to evaluate the body.
  • RegExp Match indices, which provide additional information about the start and end indices of captured substrings relative to the start of the input string.
  • An .at() method on all the built-in indexables, adding an .at() method to all basic indexable classes, including Array, String, and TypedArray. This provides a solution for “negative indexing” of JS arrays, similar to Python.
  • Class static blocks, which provide a mechanism for additional static initialization during class definition evaluation. This is not intended as a replacement for public fields but is intended to augment existing use cases while enabling new use cases not currently handled by that proposal.
  • Accessible Object.prototype.hasOwnProperty(), which provides for an Object.hasOwn() method to make Object.prototype.hasOwnProperty more accessible.
  • Error cause, for accumulating errors. The proposal calls for adding an options parameter to the Error() constructor with a cause property, the value of which will be assigned to the error instances as a property. Errors can be chained without unnecessary and overelaborate formalities on wrapping the errors in conditions.

Last June’s ECMAScript 2021 offered capabilities such as String.prototype.ReplaceAll, for replacing instances of a substring, and the AggregateErrorcode error type.

Copyright © 2022 IDG Communications, Inc.

[ad_2]

Source link

Write a comment