John-David Dalton jdalton

View JS1K Finalists.md
View gist:1148543
1 2 3 4 5 6 7 8 9 10
 
ES5Harness.registerTest( {
id: "15.3.4.5-0-1",
 
path: "TestCases/chapter15/15.3/15.3.4/15.3.4.5/15.3.4.5-0-1.js",
 
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 http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
 
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)
javascript:%2Bfunction%28%29%7Bvar%20e%3D%22document%22%2Cc%3Dtop%5Be%5D%2Cb%3Dopen%28%22about%3Ablank%22%29%2Ca%3Db%5Be%5D%3Ba.write%28%22%3Chtml%3E%3Chead%3E%3Ctitle%3ESource%20of%20%22%2Blocation.href%2B%22%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E%22%29%3Ba.body.appendChild%28a.createElement%28%22pre%22%29%29.appendChild%28a.createTextNode%28c%5Be%2B%22Element%22%5D.innerHTML%29%29%3Ba.close%28%29%7D%28%29%3B
View portfolio.md

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 [jsperf.com][5])
  • Contributor to [has.js][6]
  • JSConf.us 2010 [video][7] ([slides][8])
  • JSConf.eu 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

C:
chdir C:\cygwin\bin
set BASHHERE=%1
bash --login -i
View gist:543015
1 2 3 4 5 6 7 8 9 10
<?php
/* *
* $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.