VOOZH about

URL: http://adequatelygood.com/tag/javascript/

⇱ Adequately Good - Posts tagged “javascript”


all posts filed under javascript

Sometimes, you might want to overwrite built-in global methods like setTimeout and setInterval. If you try, you might find that it’s much harder than you think to accomplish this in every browser, particularly if you ever want to find the originals again. After a lot of painful exp...

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 ...

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...

“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...

When I interview web developers, my first JavaScript question is usually the following:

What is the difference, in JavaScript, between x = 1 and var 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...

I've been reading Coders At Work by Peter Seibel, and one question he asks in every interview is "How do you debug - print statements, debugger like gdb, or something else?". For me, print statements are my first tool for any situation. That's why Firebug is so...

Update: This advice is now totally out-of-date and wrong. Just use replace. As recent Browserscope results show, all browsers have optimized replace to be much faster than split/join. Thanks to Luigi van der Pal for pointing this out ...

This post has been migrated from my old, defunct blog at bcherry.net. The links may not work, and the formatting may be wonky.

I’ve been playing around with asynchronous Javascript for repeated large-set actions, in the hopes of generating some useful techniques for real applications. I’ve narrowed down a...

John Resig wrote a neat micro-templating Javascript function a while back. I’ve been playing with this, and have discovered two things:

  1. These templates are totally nestable. Just make an element to be templated within a temp...

It’s often very difficult to keep track of what CSS goes where. Especially when you load up on Javascript controls and files in a large application, which render markup that depends on some CSS being there. One solution is to “inline” the CSS in the JavaScript, by adding style to each element as it’s created. This works, but it’s messy. Also, browsers are heavily optimized to apply CSS, faster than any Javascript solution could be. But when you’ve got a fancy script manager like LABjs, remembering to statically link all of the important CSS is a pain. Especially so if you’re not sure at page load whethe...

This post has been migrated from my old, defunct blog at bcherry.net. The links may not work, and the formatting may be wonky.

Working in social entertainment, one of the lynchpins of the entire business is the friend selector. Without it, there is virtually no way to grow your customer base. Having a simple, effective friend selector ...


the author

Ben is a 25 year-old software engineer. He lives and works in San Francisco. Many people think he invented the term "hoisting" in JavaScript, but this is untrue.


categories