• warning: Creating default object from empty value in /home/kourge/ on line 34.
  • : Function split() is deprecated in /home/kourge/ on line 895.
  • : Function split() is deprecated in /home/kourge/ on line 895.

Cross-Domain Requests and Prototype

Ever since 3.5, cross-domain HTTP requests have been supported in Firefox. Getting this to work may seem easier and saner than piggy-backing Flash ("simply request a URL of different origin in your XMLHttpRequest!"), but unless you use jQuery, you'll realize that for some reason, cross-domain requests mysteriously fail in your JavaScript framework despite the fact that the server is correctly responding with an appropriate Access-Control-Allow-Origin header.

JavaScript Quiz and Explanations of its Answers

Update: Comments are now enabled.

In the field of linguistics, rules can be either descriptive or prescriptive. Simply put, descriptive rules tell you what can be done and prescriptive rules tell you what you shouldn't do. Many articles about JavaScript give you prescriptions: they tell you what you shouldn't do in JavaScript because it's bad practice. After learning to stay away from certain styles and patterns, though, sometimes a simple typo or brain fart can avalanche into a disaster in your code and still leave you puzzled even after attempting, descriptively, to explain what exactly happened.

kangax's JavaScript quiz, geared towards web developers, helps exactly that: finding descriptions that clarify perplexing situations. It does not test your knowledge of any DOM behavior and is focused on the ECMAScript language itself. Since this quiz targets web developers, SpiderMonkey gurus can likely even point to where a given quirk (the term is being used very loosely here) is manifested in the implementation. As always, please point out any possible error in the answer explanations about to follow. Those who are interested but still haven't taken it: halt! Go and take it. I'll wait. After that, read on.

Ubiquity commands for Drupal

Ubiquity is a dynamic command and quasi-natural language add-on for Firefox, recently released by Mozilla Labs. It sure is getting ever so popular, so I decided to write two Drupal-related Ubiquity commands in one shot: drupal and drupal-api.

Building and compiling V8 on Mac OS X

Now that Google Chrome is released, the project page and repository of the V8 JavaScript engine is revealed and available for public hacking. This guide shows how to get the source of V8 and build a V8 JavaScript shell on Mac OS X Leopard.

Google Chrome SunSpider benchmark results

I promised to post the SunSpider benchmarks for Google Chrome, and boy, V8 surely blew away other browsers in many aspects! For the visual learners, here's a pretty chart to show just how monstrous Chrome is when it comes to JS perfs (as Intchanter noted, smaller is better):

Here are some nicely formatted raw numbers:

Ubiquity Commands

I have written two Ubiquity commands so far. If you have Ubiquity installed, you should be prompted to install commands when reading this page.

Drupal tools

Drupal tools contains two commands, drupal and drupal-api.

drupal (node ID)

drupal opens the corresponding node on

drupal-api (function name) [on (drupal version)]

What Google Chrome means to web developers

With the release of Google Chrome just coming up tomorrow, by now the blogosphere should be on fire with all the screenshots and juicy details. Even though I see Google Chrome as something that means more to the user than to the developer, there are certain goodies in Google Chrome that aim to provide a better platform for developers. What's the implication for web developers here?

Prototype Essentials: just the essence

One of my recent efforts is Prototype Essentials. It is, pardon my pun, essentially Prototype stripped of its browser-specific parts such as Ajax, DOM stuff, selectors, form helpers, and an event system. Why would anyone want a stripped down version of Prototype?

The big idea is that sometimes your preferred JavaScript library or your JavaScript environment has an underpowered API when it comes to pure programming. I'll draw two of my personal examples. I find jQuery to be awesome for intuitive DOM traversal and manipulation, but when it comes to non-DOM objects, what jQuery can do is limited (and also, in my own opinion, not as intuitive). Drupal is a great platform to build web apps on, but its simplicity (bundling jQuery) comes with a cost, and I find myself constrained because of this. Not anymore.

My second example is when I'd like to throw together a quick and dirty shell script using JavaScript on Rhino. I frequently find myself in need of an intuitive way to get the last element of an array (Array.last in Prototype), interpolate strings (String.interpolate in Prototype), or construct ranges ($R or ObjectRange in Prototype). Now all I need to do now is load Prototype Essentials and I'd have a much richer set of utilities.

So please check out the website I set up for Prototype Essentials. I also plan to wrap this into a Drupal module so I can ease my pains (and hopefully those of others) in JavaScripting in Drupal.

Snippet: Font Detection with Prototype

This is essentially a clean house implementation of the font detection method described at lalit dot lab using Prototype 1.6. Another method described at seems very interesting, since it uses Flash.

This is only usable after the DOM is ready. Call Font.detect with a string containing the name of the font to be detected. If it's detected as present, true is returned, otherwise, false.

Firefox 3, Now With Array Inconsistency

Alex Russell has pointed out that Firefox 3 has some quirky issues with JavaScript arrays, namely, an array made from a literal has a different constructor than an array made from instantiating the global array object. Long story short, the below is true:

[].constructor != new Array().constructor


It seems like this is a Firebug-specific issue. If you try to evaluate the above in Error Console, you'll get false.

Syndicate content