📎 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
/dflag is used, andexecresults 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.hasOwnworks as a static alternative tohasOwnProperty, including cases such as objects created withObject.create(null).- Static class blocks run when the class is loaded and can initialize static values.
Errornow accepts acauseoption for chained error information.
