2022-01

A pipe operator for JavaScript: introduction and use cases

[2022-01-27] dev, javascript, es proposal

The proposal “Pipe operator (|>) for JavaScript” (by J. S. Choi, James DiGioia, Ron Buckton and Tab Atkins) introduces a new operator. This operator is an idea borrowed from functional programming that makes applying functions more convenient in many cases.

This blog post describes how the pipe operator works and what its use cases are (there are more than you might expect!).

Setting up symbol-valued constants via proxies

[2022-01-26] dev, javascript, proxy

Dean Tribble (via Rob Palmer) has come up with a neat trick to create constants whose values are strings with their names. With a minor change, we can use it to set up symbol-valued constants.

ECMAScript proposal: grouping Arrays via .group() and .groupToMap()

[2022-01-21] dev, javascript, es proposal

This blog post describes the ECMAScript proposal “Array grouping” by Justin Ridgewell.

structuredClone(): deeply copying objects in JavaScript

[2022-01-16] dev, javascript, jslang

Spreading is a common technique for copying objects in JavaScript:

Spreading has one significant downside – it creates shallow copies: The top levels are copied, but property values are shared.

structuredClone() is a new function that will soon be supported by most browsers, Node.js and Deno. It creates deep copies of objects. This blog post explains how it works.

Publishing and consuming ECMAScript modules via packages – the big picture

[2022-01-12] dev, javascript, esm

The ecosystem around delivering ECMAScript modules via packages is slowly maturing. This blog post explains how the various pieces fit together:

  • Packages – JavaScript’s units for software distribution
  • The three kinds of ECMAScript module specifiers
  • Providing and using packages via module specifiers in Node.js, Deno and web browsers

2021-12

New in Node.js: node: protocol imports

[2021-12-12] dev, javascript, nodejs

Node.js now supports a node: protocol for built-in modules.

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).