2021-09

ES2022 feature: class static initialization blocks

[2021-09-01] dev, javascript, es2022

The ECMAScript proposal “Class static initialization blocks” by Ron Buckton is at stage 4 and scheduled to be included in ECMAScript 2022.

For setting up an instance of a class, we have two constructs in JavaScript:

  • Field: Create (and optionally initialize) instance properties.
  • Constructor: A block of code that is executed before setup is finished.

For setting up the static part of a class, we only have static fields. The ECMAScript proposal introduces static initialization blocks for classes, which, roughly, are to static classes what constructors are to instances.

2021-08

JavaScript needs more helper functions for iteration (map, filter, etc.) – where should we put them?

[2021-08-09] dev, javascript, iteration

Iteration is a standard that connects operations with data containers: Each operation that follows this standard, can be applied to each data container that implements this standard.

In this blog post:

  • We first explore three questions:
    • How does JavaScript’s iteration work?
    • What are its quirks?
    • What do helper functions for iteration look like? Examples include iteration versions of the Array methods .map(), .filter(), and .forEach().
  • Next, we examine the pros and cons of several approaches for implementing helper functions: As methods of data containers? As functions? Etc. Two of these approaches are supported by concrete proposals.
  • The post concludes by explaining additional benefits of iteration and iteration-based helpers.

2021-07

Simple monorepos via npm workspaces and TypeScript project references

[2021-07-21] dev, typescript, esm, nodejs

A monorepo is a single repository that is used to manage multiple projects. In this blog post, we’ll explore how to set up a simple monorepo for two npm packages. All we need is already built into npm and TypeScript.

2021-06

TypeScript and native ESM on Node.js

[2021-06-30] dev, typescript, esm, nodejs

In this blog post, I’ll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.

The GitHub repository iterable is an example of a TypeScript ESM package that works on Node.js. It still uses the "typesVersions" workaround (which isn’t needed in TypeScript 4.7 and later).

Temporal: getting started with JavaScript’s new date time API

[2021-06-28] dev, javascript, es proposal

Date, JavaScript’s current date time API is infamously difficult to use. The ECMAScript proposal “Temporal” is a new and better date time API and currently at stage 3. It was created by Philipp Dunkel, Maggie Johnson-Pint, Matt Johnson-Pint, Brian Terlson, Shane Carr, Ujjwal Sharma, Philip Chimento, Jason Williams, and Justin Grant.

This blog post has two goals:

  • Giving you a feeling for how Temporal works
  • Helping you get started with it

However, it is not an exhaustive documentation: For many details, you will have to consult the (excellent) documentation for Temporal.

Warning: These are my first explorations of this API – feedback welcome!

ECMAScript proposal: Ergonomic brand checks for private fields

[2021-06-19] dev, javascript, es proposal

In this blog post, we examine the ECMAScript proposal “Ergonomic brand checks for private fields” (by Jordan Harband). It proposes a compact way for checking if an object has a given private field.

ECMAScript proposal: Accessible Object.prototype.hasOwnProperty()

[2021-06-17] dev, javascript, es proposal

In this blog post, we examine the ECMAScript proposal “Accessible Object.prototype.hasOwnProperty() (by Jamie Kyle and Tierney Cyren). It proposes a new, simpler way of checking if an object has an own (non-inherited) property.

ECMAScript proposal: JSON modules

[2021-06-16] dev, javascript, es proposal

In this blog post, we examine the ECMAScript proposal “JSON modules” (by Sven Sauleau, Daniel Ehrenberg, Myles Borins, and Dan Clark). It lets us import JSON data as if it were an ECMAScript module.

ECMAScript proposal: Error cause (chaining errors)

[2021-06-15] dev, javascript, es proposal

In this blog post, we examine the ECMAScript proposal “Error cause” (by Chengzhong Wu and Hemanth HM). It describes a feature where instances of Error can optionally specify that they were caused by another error.

2021-01

undefined vs. null revisited

[2021-01-27] dev, javascript, jshistory

Many programming languages have one “non-value” called null. It indicates that a variable does not currently point to an object – for example, when it hasn’t been initialized yet.

In contrast, JavaScript has two such non-values: undefined and null. In this blog post, we examine how they differ and how to best use or avoid them.