Saner HTML5 History Management
Hashchange
This event is quite simple. Whenever the window.location.hash
property changes, by following a link, setting the property, editing the URL bar, or ...
This event is quite simple. Whenever the window.location.hash
property changes, by following a link, setting the property, editing the URL bar, or ...
The engineering culture at Twitter requires tests. Lots of tests. I haven’t had formal experience with JavaScript testing before Twitter, so I’ve been learning a lot as I go. In particular, a number of patterns I used to use, write about, and encourage have turned out to be b...
When writing unit-tests for code, a common technique is spying, where you set expectations on a method’s invoc...
The most common co...
Like most object-oriented programming languages, JavaScript provides built-in ways to convert between objects and primitive values, by way of the special toString
and valueOf
methods. This article will cover the basics of these methods, but then dive into the details of how this stuff really works, bad stuff, performan...
One of JavaScript’s most convenient features is the object syntax. Objects are so easy to work with. You’ve got a l...
“JavaScript: Better and Faster” is the name of a presentation I gave at Slide last week. It was generally well-received by the Slide crew so I decided to put a (slightly edited) copy of the accompanying slidesho...
The module pattern is a common JavaScript coding pattern. It’s generally well understood, but there ar...
One particular weirdness and unpleasantry in JavaScript is the set of equality operators. Like virtually every language, JavaScript has the standard ==
, !=
, <
, >
, <=
, and >=
operators. However, ==
an...
I was talking with a co-worker today about the behavior of setTimeout
and setInterval
when given a small interval, like 0
or 1
. The expectation would be tha...
Take a look at this web site. Notice anything out of the ordinary. Hopef...
When I interview web developers, my first JavaScript question is usually the following:
What is the difference, in JavaScript, betweenx = 1
andvar x = 1
. Feel free to answer in as much ...
Do you know what value will be alerted if the following is executed as a JavaScript program?
var foo = 1;
function bar() {
if (!foo) {
var foo = 10;
}
alert(foo);
}
bar();
If it surprises you that the answer is “10”, then this one will probably really th...
Ever had a need to to a text search/replace through the DOM? For articles in drafting on this blog I often use the form (TODO: somethi...
>>> function F() { return function inner() { return "inner invoked"; }; }
>...
UPDATE: This technique has turned out to be dangerous in Chrome. It seems that Chrome will load the JS files into the cache, but then set an implied type="text/css" on them. This means that it will refuse to re-use them as Java...