Skip to content

Instantly share code, notes, and snippets.

View arv's full-sized avatar
👋
Reflecting...

Erik Arvidsson arv

👋
Reflecting...
View GitHub Profile
@arv
arv / node-append.js
Created October 6, 2011 21:56
Node.prototype.append
(function() {
function isNode(value) {
return value instanceof Node;
}
function isAttrObject(value) {
return value != null && typeof value === 'object' && !isNode(value);
}
var C = 1;
function f(x = C) {
var C = 2;
return x;
}
var result = f(); // ???
@arv
arv / ES5 + __proto__
Created June 1, 2012 22:16
Custom Elements
// And in browsers that support __proto__:
document.register('x-foo', {
extends: 'p',
prototype: {
__proto__: HTMLParagraphElement.prototype,
get foo() { return 'foo'; }
}
})
@arv
arv / gist:3756613
Created September 20, 2012 15:28
notify
var data = 42;
var object = {
get x() {
return data;
},
set x(v) {
notifier.notify({
type: 'updated',
name: 'x',
oldValue: data
@arv
arv / gist:3900474
Created October 16, 2012 16:45
ExportSpecifierSet
ExportSpecifierSet ::= "{" ExportSpecifier ("," ExportSpecifier)* "}" ("from" Path)?
| Id ("from" Path)?
| "*" ("from" Path)?
@arv
arv / gist:3900429
Created October 16, 2012 16:39
indent import
import {
variablesInFunction,
variablesInBlock,
thinger,
otherthinger,
...
} from '../semantics/VariableBinder.js';
Object.prototype.$super = function() {
var func = arguments.callee.caller;
var name = func.foundName_;
if (!name) {
for (var p in this) {
if (this[p] == func) {
name = p;
break;
}
}
@arv
arv / DOMImpl.js
Last active December 11, 2015 23:18
document.register with classes
// Create is defined in the latest ES6 spec. Foo[create]() is used to create the instance
// when you do "new Foo". This instance is then passed to Foo.call(instance, <args>)
import {create} from '@reflect';
Element[create] = function() {
return documemt.createElementNS(this.prototype.namespaceURI, this.prototype.localName)
};
@arv
arv / compile.sh
Last active December 17, 2015 04:59
Shows how you can build a smaller js binary to only parse (and print) some ES6 code.
traceur --out out.js parser.js
# Traceur does not strip dead code. Use Uglify2.
uglifyjs src/runtime/runtime.js out.js -cm -o out.min.js
@arv
arv / soduko.js
Last active December 18, 2015 08:28 — forked from BrendanEich/gist:5753666
ES6 syntax
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {