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 / gist:e4b7116aefcec840e9cf
Created Jun 20, 2014
experimenting witn alternatives new semantics for ES6
View gist:e4b7116aefcec840e9cf
//The following is essentially the current ES6 spec. for Boolean, expressed in ES code
//$$foo calls are performing spec. level operations that don't have direct ES language equivalents
class Boolean {
static [Symbol.create](.){
//@@create allocates the object with private slots but doesn't do any slot initialization
return $$OrdinaryDateFromConstructor(this,"%BooleanPrototype%",["[[BooleanData]]"]);
// a newly created Boolean instance has undefined as the value of its [[BooleanData]] internal slot.
// the undefined value indicates that the instance has not yet been initialized by the constructor function
}
@allenwb
allenwb / enumerate.js
Created Jul 18, 2014
[[Enumerate]] in JS code
View enumerate.js
function *enumerate(obj) {
if (Object(obj)!==obj) return undefined;
let visited = new Set;
while (obj!==null ) {
for (name of Object.getOwnPropertyNames(obj)) {
if (!visited.has(name)) {
let desc = Object.getOwnPropertyDescriptor(obj,name);
if (desc) {
visited.add(name);
if (desc.enumerable) yield name;
@allenwb
allenwb / 0option1ConstructorSummary.md
Last active Aug 29, 2015
New ES6 constructor features and semantics: Alternative 1 auto allocation in derived classes
View 0option1ConstructorSummary.md

New ES6 Constructor Semantics and Usage Examples

Auto super: Alternative Design where subclass constructors automatically call their superclass constructors

This Gist presents a new design of class-based object construction in ES6 that does not require use of the two-phase @@create protocol.

One of the characteristics of this proposal is that subclasses constructors automatically super invoke their superclass constructor's object allocation and initialization logic unless the derived constructor expliictly assigns to this.

An alternative version of this proposal eliminates from the design most implicit/automatic invocations of superclass constructors.

In addition to the material below, there is a seperate design rationale covering several key features that are common to both designs.

View new instantation rationale.md

At the July 2014 TC39 meeting, we presented a sketch of a new object instantiation design that was inspired from posting of Claude Pache. Here's the basic idea, as originally described by Claude:

If a constructor C uses super in its code, let’s say:

  class C extends B {
      constructor(...args) {
          /* 1: preliminary code that doesn't contain calls to a super-method */
          // ...

          /* 2: call to a super-constructor */
@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
@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 / 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 / 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 / species.md
Last active Nov 18, 2015
A FAQ on the Design of the ECMAScript 2016 @@species protocol
View species.md

####Why is .constructor not good enough? What does doing .constructor[@@species] add?

@@species is an extension point that allows abstract algorithms that may be inherited by (or applied to) various subclasses with differing characteristics to decouple the class of the objects generated by an application of the method from the actual class of the objects the method was applied to. This is a realivately rare situation, but one that does infact occur when developing relatively complex class hierarchies such as a collections hierarchy.

The first known usage of the species pattern that I’m aware of (and the origin of the name species) was in the Smalltalk-80 collection hierarchy. For example, the Smalltalk-80 collection hierarchy includes a class called SortedCollection. SortedCollection is a subclass of OrderedCollection (essentially a double ended queue, similar to a JS Array) except that whenever a new element is added to the collection, the value ordering of the collection is resorted. The familiar operat

View Object.isAncestorOf
Object.isAncestorOf = function isAncestorOf(parent,child) {
if (child===null || child===undefined) return false;
if (parent === null) return true;
child = Object(child);
var proto = Object.getPrototypeOf(child);
if (proto === parent) return true;
return isAncestorOf(parent,proto);
}
You can’t perform that action at this time.