Skip to content

Instantly share code, notes, and snippets.

View arv's full-sized avatar
👋

Erik Arvidsson arv

👋
View GitHub Profile
@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) {
@arv
arv / gist:6528418
Created September 11, 2013 19:17 — forked from sorvell/gist:6527156
<!DOCTYPE html>
<html>
<head>
<script src="../polymer/polymer.js"></script>
</head>
<body>
<template id="host-template">
<div>host shadowRoot</div>
<content></content>
</template>
@arv
arv / Document.registor.md
Last active December 30, 2015 19:38
document.register with a functionThe main difference between this and the current LC is that it takes a Function object instead of an Object. The Function's @@create method is updated to create instances that are real elements.

Register

When called, the register method must run these steps:

Input

  • ENVIRONMENT, the unit of related similar-origin browsing contexts
  • DOCUMENT, the context object of the method
  • NAME, the custom element name of the element being registered
  • FUNCTION, the custom element constructor function, optional
@arv
arv / Branded.js
Last active August 29, 2015 13:56
Secure shadow dom
(function() {
'use strict';
function uncurryThis(f) {
return f.call.bind(f);
}
var ShadowRoot = window.ShadowRoot;
var createShadowRoot = uncurryThis(Element.prototype.createShadowRoot);
var ownerDocumentGetter = uncurryThis(Object.getOwnPropertyDescriptor(Node.prototype, 'ownerDocument').get);
@arv
arv / createAttributeNS.js
Created March 13, 2014 14:55
Implementation of createAttributeNS and setAttributeNodeNS
if (!Document.prototype.createAttributeNS) {
Document.prototype.createAttributeNS = function(namespaceURI, qualifiedName) {
var dummy = this.createElement('dummy');
dummy.setAttributeNS(namespaceURI, qualifiedName, '');
var attr = dummy.attributes[0];
dummy.removeAttributeNode(attr);
return attr;
};
}
@arv
arv / designer.html
Created June 3, 2014 15:59
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../google-map/google-map.html">
<polymer-element name="my-element">
@arv
arv / x.md
Last active August 29, 2015 14:02
@@new and @@create
class B {
  constructor(x) {
    this.x = x;
  }
  static [Symbol.create]() {
    var o = super();
    weakMap.set(o, 123456789);  // Dom wrapper foo
    return o;
 }
@arv
arv / 13.10.4.md
Last active August 29, 2015 14:02
Unscopables spec update

13.10.4 Runtime Semantics: Evaluation

WithStatement : with ( Expression ) Statement

  1. Let val be the result of evaluating Expression.
  2. Let obj be ToObject(GetValue(val)).
  3. ReturnIfAbrupt(obj).
  4. Let oldEnv be the running execution context’s LexicalEnvironment.
  5. Let newEnv be NewObjectEnvironment(obj, oldEnv).
@arv
arv / 0_reuse_code.js
Created July 16, 2014 14:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@arv
arv / gist:d9082aea49e47657bc21
Last active August 29, 2015 14:04
Custom Elements with @@create

At the July TC39 meeting we decided to explore removing @@create in favor of a model where super() in a [[Construct]] call creates the instance object. To correctly know how to create the instance and set the prototype a [[Construct]] call gets an implicit receiver which is the constructor function new was called with.

class Base {
  constructor() {
    var object = Object.create(new*.prototype);  // new binding needs new syntax...
                                                 // bikeshed...
    myWeakMap.set(object, myHiddenData);
    return object;
 }