Skip to content

Instantly share code, notes, and snippets.

bterlson / box.js
Created Sep 30, 2020
Source code for a useless box.
View box.js
import Servo from "pins/servo";
import Timer from "timer";
import Digital from "pins/digital";
import Monitor from "pins/digital/monitor";
import NeoPixel from "neopixel";
const doorServo = new Servo({pin: 5});
const armServo = new Servo({pin: 14});
const switchMonitor = new Monitor({
mode: Digital.InputPullUp,
View decmeta.js
let editableThings = new WeakMap();
function finisherFor(prop) {
return function finisher(C) {
let list = editableThings.get(C);
if (!list) {
list = [];
editableThings.set(C, list);

Keybase proof

I hereby claim:

  • I am bterlson on github.
  • I am bterlson ( on keybase.
  • I have a public key ASCWavsVAlIX8j8m9UksFEDYdOCGjuLVELH-bE3z9KOY3wo

To claim this, I am signing this object:

View figure2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
bterlson / mod.js
Last active Jan 26, 2017
Module export forms have subtle differences
View mod.js
// exporter1.js
let foo = 1;
export { foo as default }; // exports the foo binding
foo = 2;
// exporter2.js
let foo = 1;
export default foo; // creates a new binding named *default* and initializes it to 1.
foo = 2; // assigns to the foo binding which is not exported

Test file

let obj = {};
Object.defineProperty(obj, 'a', { enumerable: true, configurable: true });
Object.defineProperty(obj, 'b', { enumerable: true, configurable: true });
Object.defineProperty(obj, 'c', { enumerable: true, configurable: true });

let visited = []
for(prop in obj) {
  Object.defineProperty(obj, 'c', { enumerable: false });
View eshost-output.txt
> eshost host --list
│ name │ type │ path │ args │
│ chakra │ ch │ C:\Users\brterlso\projects\runify\hosts\ch.exe │ │
│ node │ node │ c:\Program Files\nodejs\node.exe │ │
│ spidermonkey │ jsshell │ C:\Users\brterlso\projects\runify\hosts\js.exe │ │

Pattern Matching

This is a strawman proposal for adding pattern matching to ECMAScript. Pattern matching is useful for matching a value to some structure in a similar way to destructuring. The primary difference between destructuring and pattern matching are the use cases involved - destructuring is useful for binding pieces out of larger structures whereas pattern matching is useful for mapping a value's structure to data or a set of behaviors. In practice this means that destructuring tends to allow many shapes of data and will do its best to bind something out of it, whereas pattern matching will tend to be more conservative.

Additionally, the power of pattern matching is increased substantially when values are allowed to participate in the pattern matching semantics as a matcher as well as a matchee. This proposal includes the notion of a pattern matching protocol - a symbol method that can be implemented by objects that enables developers to use those values in pattern matching. A common scenario w