Skip to content

Instantly share code, notes, and snippets.

Allen Wirfs-Brock allenwb

Block or report user

Report or block allenwb

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
@allenwb
allenwb / mapreviver.js
Created Oct 5, 2012
A JSON.parse reviver from ES6 maps
View mapreviver.js
function mapReviver(key, value) {
if (typeof value != "object") return value;
switch (value["<kind>"]){
case undefined: return value;
case "Map": {
let newValue = new Map;
let mapData = value["<mapData>"];
if (!mapData) return value;
mapData.forEach(e=>newValue.set(e[0], e[1]));
return newValue;
@allenwb
allenwb / short-functions.js
Created Mar 11, 2012 — forked from dherman/short-functions.js
using do () {} for concise functions
View short-functions.js
// 1. No new syntax for non-TCP functions.
//
// This approach does do include a shorter syntax for regular functions, so if a classic JS function
// is what you want you use the classic long form function expression:
a.some(function (x){
if (invalid(x))
return true;
console.log(x);
});
@allenwb
allenwb / introspectNumber.js
Created Mar 4, 2012
A hypothetical Number mirror factory that distingishes between number values and number objects
View introspectNumber.js
Number.prototype.introspect = function() {
"use strict"; //.See ES5.1 10.4.3 steps 1-3
if (typeof this == "object") return Object.prototype.introspect.call(this);//generic object mirror
return new Float(+this); //Number value mirror
};
@allenwb
allenwb / gist:1861530
Created Feb 19, 2012
JavaScript utf-16 JSON round-tripping experiment
View gist:1861530

This is a response to Git 1850768 For some reason the following wouldn't post as a comment

@mranney @piscisaureus

I did some experiments and I don't see any round-tripping issues showing up, at least in FF:

var z= "\ud83d\ude38";   //u+1f638
console.log("z.length: " + z.length);  //expect 2
@allenwb
allenwb / minimalist-classes.js
Created Nov 2, 2011 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
View minimalist-classes.js
//work in progress
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// and BrendanEich's Rich Corinthian Leather alternative proposal
//intro and justifications still to come
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
You can’t perform that action at this time.