Skip to content

Instantly share code, notes, and snippets.

Brian Terlson bterlson

Block or report user

Report or block bterlson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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);
}
list.push(prop);
View keybase.md

Keybase proof

I hereby claim:

  • I am bterlson on github.
  • I am bterlson (https://keybase.io/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
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
View test-enumerate.md

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 │ │
├──────────────┼─────────┼────────────────────────────────────────────────────┼─────────┤
View patternmatching.md

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

View classy.js
class A { }
class B extends A {
method() { super.x = 1; return super.x; }
}
var b = new B();
b.method(); // undefined (no property x on A.prototype or above)
b.hasOwnProperty('x'); // true (own property created on receiver by [[set]])
class C extends B {
get x() { return "gotten" }
@bterlson
bterlson / example.js
Created Jun 5, 2015
Async constructors?
View example.js
async function Person() {
this.name = await getName();
}
// seems weird-ish.
var p = new Person();
p.then(person => console.log(person.name));
// but seems better in another async function
async function CreatePerson() {
You can’t perform that action at this time.