2016-08

ES2019: Function.prototype.toString revision

[2016-08-31] dev, javascript, es2019

The ECMAScript proposal “Function.prototype.toString revision” (by Michael Ficarra) is at stage 4 and therefore part of ECMAScript 2019. It brings two major improvements compared to ES2016:

  • Whenever possible – source code: If a function was created via ECMAScript source code, toString() must return that source code. In ES2016, whether to do so is left up to engines.
  • Otherwise – standardized placeholder: In ES2016, if toString() could not (or would not) create syntactically valid ECMAScript code, it had to return a string for which eval() throws a SyntaxError. In other words, eval() must not be able to parse the string. This requirement was forward-incompatible – whatever string you come up with, you can never be completely sure that a future version of ECMAScript doesn’t make it syntactically valid. In contrast, the proposal standardizes a placeholder: a function whose body is { [native code] }. Details are explained in the next section.

2016-06

Taking a break

[2016-06-16] 2ality

For health reasons, I’m taking June–August off from work (Twitter, blogging, etc.). See you in September!

2016-05

Six nifty ES6 tricks

[2016-05-22] dev, javascript, esnext

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

Handling whitespace in ES6 template literals

[2016-05-15] dev, javascript, esnext, template literals

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

2016-04

Trees of Promises in ES6

[2016-04-17] dev, javascript, esnext, async, promises

This blog post shows how to handle trees of ES6 Promises, via an example where the contents of a directory are listed asynchronously.

Tracking unhandled rejected Promises

[2016-04-12] dev, javascript, esnext, async, promises

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() rejects the Promise it returns then that rejection will never be handled anywhere.

Let’s look at how you can track unhandled rejections in browsers and in Node.js.

2016-03

Promise-based functions should not throw exceptions

[2016-03-25] dev, javascript, esnext, async, promises

This blog post gives tips for error handling in asynchronous, Promise-based functions.

The need for multi-platform npm packages

[2016-03-20] dev, javascript, esnext, npm, jsmodules

In this blog post, I argue that it should be possible to have multiple implementations of the same npm package (same name, same version).

2016-02

Arrow functions vs. bind()

[2016-02-24] dev, javascript, esnext, coding

ES6 arrow functions are often a compelling alternative to Function.prototype.bind().

Examples of name clashes in JavaScript’s standard library

[2016-02-22] dev, javascript, esnext

The main use case for ES6 symbols is that you can use them as property keys that can’t clash with other property keys.

In case you think that name clashes don’t matter, here are three examples of where name clashes caused problems in the evolution of the JavaScript standard library: