↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

8 new JavaScript features to start using today

ECMAScript 2022 adds eight JavaScript features the article presents as usable now. It groups them around class fields, regular expressions, module loading, object property checks, array indexing, static initialization, and error chaining.

Reading notes
#

  • Public and private instance fields can be declared in the class body instead of only in the constructor.
  • Private instance methods and accessors also use the hash prefix and have the same visibility rules as private fields.
  • Static members belong to the class, not to instances, and can also be private.
  • RegExp match indices are available when the /d flag is used, and exec results then include start and end positions for matches and named groups.
  • Top-level await lets a module wait on dependent asynchronous work before the importing module runs.
  • Ergonomic brand checks let code test for a private field with #fieldName in object.
  • .at() supports negative indices on built-in indexable values.
  • Object.hasOwn works as a static alternative to hasOwnProperty, including cases such as objects created with Object.create(null).
  • Static class blocks run when the class is loaded and can initialize static values.
  • Error now accepts a cause option for chained error information.