John-David Dalton jdalton

View JS1K
View gist:1148543
1 2 3 4 5 6 7 8 9 10
ES5Harness.registerTest( {
id: "",
path: "TestCases/chapter15/15.3/15.3.4/",
description: "Function.prototype.bind must exist as a function",
test: function testcase() {
var f = Function.prototype.bind;
View gist:1120592

Incorrect ES5 fallbacks

Over the weekend I implemented a few Array methods in plain JavaScript to avoid recently patched Rhino bugs. That got my thinking about ES5 fallback implementations in various JavaScript libs/frameworks/transpilers. I decided to compile a not-so-complete list of ES5 related discrepancies found in many of them. Differences in native vs. fallback implementations create cross-browser inconsistencies and increase the chance of usage errors. I hope this post will raise awareness of just how hard it is to follow spec (during my research I found a few issues in my own projects too). All library developers should to take a closer look at their code and make the small changes needed to follow the specification (especially if your code forks for native methods).

Common Issues

Most implementations suffer from the following

View ios-viewport-scaling-bug-fix-original.js
1 2 3 4 5 6 7 8 9 10
// Original code from
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
View gist:812950
  1. Feature Testing

    Check for the existence of a method and checks that it returns the correct output

  2. Feature Detection

    Check for the existence of a method

  3. Weak Inference

View gist:799954
1 2
// mobile bookmarklet for "view source" (probably over encoded)

John-David Dalton's Portfolio

  • Creator of the [FuseJS][1] JavaScript framework ([on GitHub][2])
  • Creator of [Fusebox][3] (sandboxed natives)
  • Contributor to [benchmark.js][4] (used by [][5])
  • Contributor to [has.js][6]
  • 2010 [video][7] ([slides][8])
  • 2010 [video][9]
  • Script Junkie [article][10]
  • Performance Calendar [article][11]
View gist:704635
View gist:615070

How to customize the Cygwin default directory

1) Edit C:\cygwin\Cygwin.bat

@echo off

chdir C:\cygwin\bin
bash --login -i
View gist:543015
1 2 3 4 5 6 7 8 9 10
/* *
* $chars is an array of char codes from your js file
* created ahead of time using a small js snippet. This
* avoids issues PHP has with reading characters that have a
* higher char code than 127:
* var code = "your code here", i = -1, length = code.length, result = [];
* while (++i < length) {
* result.push(i + " => " + code.charCodeAt(i));
Something went wrong with that request. Please try again.