In this blog post, we explore how arbitrary ASCII text can be encoded as Unicode clock faces: > clocksToPlain('') 'Hello!' I’m explaining ideas by Maggie Pint and @FakeUnicode. Unicode clock faces The following times are available as clock ... more
In this blog post I present Communicating Sequential Processes (CSP) and how they can be used as an alternative to async generators. In the process, we will also take a look at the ECMAScript proposal that async generators are a part of: “asynchronous ... more
This blog post tracks what features may be included in ES2018. I will continually update it. Proposed ECMAScript 2018 features Recall that every ECMAScript feature proposal goes through stages: Stage 4 means that a feature will be in the next release ... more
babel-preset-env is a new preset that lets you specify an environment and automatically enables the necessary plugins. The problem At the moment, several presets let you determine what features Babel should support: babel-preset-es2015 , babel-preset-es2016 ... more
The ECMAScript proposal “Shared memory and atomics” by Lars T. Hansen has reached stage 4 this week and will be part of ECMAScript 2017. It introduces a new constructor SharedArrayBuffer and a namespace object Atomics with helper functions. This blog ... more
In this blog post, you’ll learn: How a proposed “spec mode” for Babel makes transpiled ES modules more spec-compliant. That will help with preparing for native ES modules. How ES modules and CommonJS modules will interoperate on Node.js. How far along ... more
Occasionally, you want Web Workers to communicate with each other. Doing so is not obvious as most Web Worker examples are about communicating between the main thread and a Web Worker. There, one uses postMessage() to send messages directly to the Worker. ... more
The ECMAScript proposal “ import() ” by Domenic Denicola is currently at stage 3. It enables dynamic loading of ECMAScript modules and is explained in this blog post. ECMAScript modules are static ECMAScript modules are completely static: you must specify ... more
The following function evalCode() traces the global variables that are accessed while evaluating a piece of JavaScript code. // Simple solution const _glob = typeof global !== 'undefined' ? global : self; function evalCode(code) { const func = new Function ... more
In this blog post, we look at a syntactic puzzle. This is just for fun; there is nothing useful you can do with what we examine. It may, however, make you more aware of how JavaScript works, syntactically. Question What do you need to do to get the following ... more
An ES6 proxy lets you intercept and customize operations performed on an object, its so-called target . Interception and customization is handled via a handler object (think even listener). Operations are intercepted by handler methods. If a handler ... more
This blog post describes what you can do with functions that return tag functions for ES6 template literals. For an introduction to template literals, tagged template literals and tag functions, consult chapter “Template literals” in “Exploring ES6”. ... more
This blog post covers three ways of understanding Promises. This is an example of invoking a Promise-based function asyncFunc() : function asyncFunc() { return new Promise((resolve, reject) => { setTimeout(() => resolve('DONE'), 100); }); } asyncFunc() ... more
This blog post gives tips for using async functions. If you are unfamiliar with them, you can read chapter “Async functions” in “Exploring ES2016 and ES2017”. Know your Promises The foundation of async functions is Promises. That’s why understanding ... more
The ECMAScript proposal “Asynchronous Iteration” by Domenic Denicola is currently at stage 3. This blog post explains how it works. Asynchronous iteration With ECMAScript 6, JavaScript got built-in support for synchronously iterating over data. But what ... more
The ECMAScript proposal “Rest/Spread Properties” by Sebastian Markbåge is currently at stage 3. It enables: The rest operator ( ... ) in object destructuring. At the moment, this operator only works for Array destructuring and in parameter definitions. ... more
The ECMAScript proposal “ global ” by Jordan Harband is currently at stage 3. It provides a new standard way of accessing the global object. Referring to the global object The following are a few popular ways of referring to the global object: Global ... more
As of version 6, Babel supports presets , sets of features that can be enabled together. This blog post looks at three new useful Babel presets. Complementing babel-preset-es2015 These two presets are useful complements to babel-preset-es2015 (for ES6): ... more
I really like the way EJS templates work, because the meta-language (loops, if-then-else, etc.) is just JavaScript. This blog post describes ideas for improving their syntax. EJS templates This is an example of an EJS template: <ul> <% for(var ... more
This blog post describes a new setup for presenting with Apple’s Keynote app that I’ve experimented with. It involves: A Mac running Keynote An iOS device (iPhone or iMac) The wish For presentations, mirroring the laptop’s display with the projector’s ... more
The ECMAScript proposal “Template Literal Revision” by Tim Disney is currently at stage 3. It proposes to give the innards of tagged template literals more syntactic freedom. Tag functions and escape sequences With tagged template literals, you can make ... more
The ECMAScript proposal “ Function.prototype.toString revision” by Michael Ficarra is currently at stage 3. It brings two major improvements compared to ES2016: If a function was created via ECMAScript source code, toString() must return that source ... more
For health reasons, I’m taking June–August off from work (Twitter, blogging, etc.). See you in September! To tide you over, you can read (and buy, to support my work) my books, which are free to read online: Speaking JavaScript Exploring ES6 Setting ... more
In this blog post, I show six tricks enabled by new ES6 features. At the end of each section, I point to related material in my book “Exploring ES6” (which is free to read online). Enforcing mandatory parameters via parameter default values ES6 parameter ... more
In this blog post, we look at problems that arise when template literals contain whitespace: Breaking up long lines Dedenting content Joining Arrays Indenting inserted content I’m using the library common-tags by Declan de Wet (with “useful template ... more
This blog post shows how to handle trees of ES6 Promises, via an example where the contents of a directory are listed asynchronously. The challenge We’d like to implement a Promise-based asynchronous function listFile(dir) whose result is an Array with ... more
In Promise-based asynchronous code, rejections are used for error handling. One risk is that rejections may get lost, leading to silent failures. For example: function main() { asyncFunc() .then(···) .then(() => console.log('Done!')); } If asyncFunc() ... more
Promise-based functions should only ever reject the Promises they return, they should never throw exceptions. The reason is that doing so would disrupt Promise-based error handling: function asyncFunc() { return doSomethingAsync() // (A) .then(result ... more
In this blog post, I argue that it should be possible to have multiple implementations of the same npm package (same name, same version). The problem At the moment, when you write an npm package, you can specify on what platforms it works, via the package.json ... more
ES6 arrow functions are often a compelling alternative to Function.prototype.bind() . Extracting methods If an extracted method is to work as a callback, you must specify a fixed this , otherwise it will be invoked as a function (and this will be undefined ... more