Category Archives: Javascript

Shortcut Element Access

Typing out document.getElementById can get a little tedious after a while. One of the best alternatives I’ve seen takes advantage of a little known feature of Javascript (and oddly enough C/C++ and possible Java): the dollar sign ($) is a valid identifier character.

Consider the following code:

function searchWasSubmitted() { var e= $(”searchField”); [...]

The Magic Eval

One of the coolest aspects of Javascript is the eval function. It gives you the option of executing code composed on the fly or received as the result of an XMLHttpRequest.

But eval can be tricky and extremely frustrating. Let’s dive into some of the most critical aspects…

For a Good Time, Call

The call method of every function gives you the power.

Javascript Has No Class

Efforts underway for JavaScript 2.0 (AKA ECMAScript Edition 4) notwithstanding, JavaScript doesn’t really have classes. Not classes like you’re familiar with in Objective-C, C++, or Java.

Just because JavaScript doesn’t support classes, doesn’t mean you can’t write really sophisticated object-oriented applications. You just have to understand the power of prototype inheritance and give up your fear [...]

Ajaxian Limitation

I was just thinking about adding another Ajax-y feature to the site when it occurred to me: I can either return JavaScript or HTML but not both.

Typically when returning HTML using an XMLHttpRequest object I set the innerHTML property of a div on the page with the result (provided the operation was successful). But I’m [...]