Skip to content

Instantly share code, notes, and snippets.

Kevin Smith zenparsing

Block or report user

Report or block zenparsing

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
@zenparsing
zenparsing / optional-chaining-proxy.js
Last active Nov 22, 2018
Optional chaining with JS Proxy
View optional-chaining-proxy.js
const unwrapSymbol = Symbol();
function unwrap(x) {
if (this == null)
return this;
let f = this[unwrapSymbol];
if (typeof f !== "function")
@zenparsing
zenparsing / jake.js
Last active Aug 29, 2015
jQuery Reimagined
View jake.js
/* Redefine jQuery methods as "raw" methods */
(function($) { "use strict";
function wrap(method) {
return function() {
var jq = $(this),
result = jq[method].apply(jq, arguments);
View jquery-direct.js
(function($) { "use strict";
function wrap(method) {
return function() {
var jq = $(this),
result = jq[method].apply(jq, arguments);
if (result && result.constructor === $)
@zenparsing
zenparsing / abstract-references.md
Last active Aug 29, 2015
Abstract References for ECMAScript
View abstract-references.md

Abstract References for ECMAScript

Overview and Motivation

Despite its functional programming facilities, ECMAScript exhibits a strong preference for object-oriented "left-to-right" composition using instance methods. Unfortunately, composition by means of instance methods requires that extensibility be achieved by adding function-valued properties to the object or a prototype ancestor of the object. This leads to the following difficulties:

@zenparsing
zenparsing / dedent-template.js
Last active Nov 19, 2019
Dedenting Template Strings
View dedent-template.js
function dedent(callSite, ...args) {
function format(str) {
let size = -1;
return str.replace(/\n(\s+)/g, (m, m1) => {
if (size < 0)
size = m1.replace(/\t/g, " ").length;
View measure-await.js
async function queueAlways() {
let x;
for (let i = 0; i < 100000; ++i)
x = await i;
}
async function queueIf() {
@zenparsing
zenparsing / async-io-1.js
Last active Aug 29, 2015
Reading and Writing Files with Async Generators
View async-io-1.js
/*
This example uses an inner generator and skips over the first iteration in order to
prevent data loss which occurs on the first call to next.
*/
import * as FS from "async-fs";
export function readFile(path) {
@zenparsing
zenparsing / Promise.js
Created Dec 28, 2013
Minimal ES6 Promise
View Promise.js
function enqueueMicrotask(fn) {
// Enqueue a function on the System-defined FIFO
// microtask queue.
}
var $status = "Promise#status",
$value = "Promise#value",
$onResolve = "Promise#onResolve",
$onReject = "Promise#onReject";
@zenparsing
zenparsing / strict-error-detection.md
Last active Dec 30, 2015
Simplified algorithm for detection of strict-mode errors in ECMAScript 6.
View strict-error-detection.md

A context object is associated with any AST node which may have "strictness". Each context has a strictness state: UNKOWN, STRICT, and NOT_STRICT. In order to account for arrow functions, parenthesized expressions are also assigned a context.

When a context C is pushed:

  • set C.parent to the current context object
  • set C.strictError to null
  • if C.parent.strict is STRICT
    • set C.strict to STRICT
  • else
    • set C.strict to UNKNOWN
View gist:7662879
// Use this gist to get syntax highlighted code for use in word processors. Just preview a comment
// that contains code.
You can’t perform that action at this time.