Skip to main content

Import assertions

· 3 min read
Dan Clark ([@dandclark1](https://twitter.com/dandclark1)), assertive importer of import assertions

The new import assertions feature allows module import statements to include additional information alongside the module specifier. An initial use for the feature is to enable JSON documents to be imported as JSON modules:

Private brand checks a.k.a. `#foo in obj`

· 3 min read
Marja Hölttä ([@marjakh](https://twitter.com/marjakh))

The in operator can be used for testing whether the given object (or any object in its prototype chain) has the given property:

const o1 = {'foo': 0};
console.log('foo' in o1); // true
const o2 = {};
console.log('foo' in o2); // false
const o3 = Object.create(o1);
console.log('foo' in o3); // true

The private brand checks feature extends the in operator to support private class fields:

class A {
  static test(obj) {
    console.log(#foo in obj);
  }
  #foo = 0;
}

A.test(new A()); // true
A.test({}); // false

class B {
 #foo = 0;
}

A.test(new B()); // false; it's not the same #foo

Since private names are only available inside the class which defines them, the test must also occur inside the class, for example in a method like static test above.

Subclass instances receive private fields from the parent class as own-properties:

class SubA extends A {};
A.test(new SubA()); // true

But objects created with with Object.create (or that have the prototype set later via the __proto__ setter or Object.setPrototypeOf) don't receive the private fields as own-properties. Because private field lookup only works on own-properties, the in operator does not find these inherited fields:

Class static initialization blocks

· 2 min read
Shu-yu Guo ([@_shu](https://twitter.com/_shu))

The new class static initialization block syntax lets developers gather code that should run once for a given class definition and put them in a single place. Consider the following example where a pseudo-random number generator uses a static block to initialize an entropy pool once, when the class MyPRNG definition is evaluated.

`Intl.DisplayNames`

· 4 min read
Shu-yu Guo ([@_shu](https://twitter.com/_shu)) and Frank Yung-Fong Tang

Web applications that reach a global audience need to show the display names of languages, regions, scripts, and currencies in many different languages. The translations of those names require data, which is available in the Unicode CLDR. Packaging the data as part of the application incurs a cost on developer time. Users are likely to prefer consistent translations of language and region names, and keeping that data up to date with the world's geopolitical happenings requires constant maintenance.

Fast, parallel applications with WebAssembly SIMD

· 10 min read
Deepti Gandluri ([@dptig](https://twitter.com/dptig)), Thomas Lively ([@tlively52](https://twitter.com/tlively52)), Ingvar Stepanyan ([@RReverser](https://twitter.com/RReverser))

SIMD stands for Single Instruction, Multiple Data. SIMD instructions are a special class of instructions that exploit data parallelism in applications by simultaneously performing the same operation on multiple data elements. Compute intensive applications like audio/video codecs, image processors, are all examples of applications that take advantage of SIMD instructions to accelerate performance. Most modern architectures support some variants of SIMD instructions.

RegExp match indices

· 5 min read
Maya Armyanova ([@Zmayski](https://twitter.com/Zmayski)), regularly expressing new features

JavaScript is now equipped with a new regular expression enhancement, called “match indices”. Imagine you want to find invalid variable names in JavaScript code that coincide with reserved words, and output a caret and an “underline” under the variable name, like:

`String.prototype.replaceAll`

· 4 min read
Mathias Bynens ([@mathias](https://twitter.com/mathias))

If you’ve ever dealt with strings in JavaScript, chances are you came across the String#replace method. String.prototype.replace(searchValue, replacement) returns a string with some matches replaced, based on the parameters you specify: