Skip to content

Instantly share code, notes, and snippets.

View globals.md

globalThis

  • PRO: almost shipping in Chrome, maybe used elsewhere
  • PRO: is actually correct
  • CON: might confuse JS beginners

Global

  • PRO: maybe less likely to confuse beginners
  • PRO/CON: looks like a namespace
  • CON: requires even more churn on this proposal
@bakkot
bakkot / es2016..es2017.md
Last active May 4, 2017
normative es2017 changes
View es2016..es2017.md
  1. d28ebe6d Normative: Specify Date.UTC when called with fewer than two arguments (#642)

  2. 0916d813 Normative: Use explicit comparison to compare two lists in Valid Chosen Reads

  3. 90ed6ce2 Normative: Call NumberToRawBytes instead of the conversion operation to get the byte values list in Atomics.compareExchange

  4. 7949fae4 Normative: Only check for undefined count parameter in Atomics.wake, because it's not marked as optional

  5. a4d0e490 Normative: Unconditionally call ToNumber on the timeout parameter in Atomics.wait, because it's not marked as optional

View onerror.js
let frame = document.body.appendChild(document.createElement('iframe'));
frame.addEventListener('load', ()=>{
let w = frame.contentWindow;
let evt;
w.addEventListener('error', e=>{evt = e;});
let scr = w.document.createElement('script');
scr.text = 'throw 42;';
View B.3.3.js
var p = () => console.log(f);
{
p(); // undefined
console.log(f); // function f(){}
f = 1;
p(); // undefined
console.log(f); // 1
View keybase.md

Keybase proof

I hereby claim:

  • I am bakkot on github.
  • I am bakkot (https://keybase.io/bakkot) on keybase.
  • I have a public key whose fingerprint is FD44 B8F2 65AC E177 48C5 23C8 A07A 119B 504C 8D8F

To claim this, I am signing this object:

View urls
https://www.googleapis.com/download/storage/v1/b/chromium-browser-continuous/o/Win%2F100056%2Fchrome-win32.zip?generation=1&alt=media
View es6-fd-block-scoping.js
(function () {
var g, h;
function x() { f = ""; }
function y() { h = f; }
{
// var-scoped f is undefined, let-scoped f is a function
f = 1; // let-scoped f gets value 1
x(); // var-scoped f gets value ""
y(); // h gets value of var-scoped f
function f() {} // var-scoped f gets value of let-scoped f
@bakkot
bakkot / ldbe.py
Created Oct 15, 2015
investigating a hypothesis about graphs
View ldbe.py
import networkx as nx
from collections import deque
import random
random.seed(42) # determinism!
def unique(l):
return len(l) == len(set(l))
def canonical(path): # path is a tuple. should also ensure sub-cycles are canonized, really, but fuck it
# picks the minimum-valued starting point.
@bakkot
bakkot / horrifying.js
Last active Apr 11, 2019
Various really bad JavaScript
View horrifying.js
(function x(){"use strict"; x = 1;}()); // TypeError
(function x(){x = 1; return x !== 1;}()); // write fails silently; function returns true
(function x(){"use strict"; x = (function(){throw 0;})();})() // Error 0
// These three lines rely on ES6.
(function x(){const x = 1;})() // No-op. In particular, not a redeclaration of x.
(function (){"use strict"; const x = 1; x = 2;})() // TypeError
(function (){const x = 1; x = 2;})() // TypeError. contrast (function x(){x = 2;}());
@bakkot
bakkot / gist:375f1d1cc07d69181d9e
Created Apr 1, 2015
SSC floater fixed position
View gist:375f1d1cc07d69181d9e
javascript:(function(){document.querySelector('.comments-floater').style.position='absolute';})()
You can’t perform that action at this time.