Get mp3 Michael Buble Pitbull MP3 search Gipsy Kings Nat King Cole All mp3 genres Coil Neil Young Suzy Solar Shakira Eva Cassidy Stevie Ray Vaughan Cobra Starship Useless Pickles » 2006 » June

Archive for June, 2006

Javascript’s null Value Has an Identity Crisis

Monday, June 12th, 2006

I came across another identity crisis in Javascript while working on my $class library. This time, it is the null value that needs help. Observe the output of the following expressions:


This time, all browsers agree: null is an “object”, but not an instance of Object. What does it mean? The way I see it, you can not use null as an Object, so it should have no relation to Object at all. You cannot access or create properties on null, you cannot evaluate null.toString(), etc.

My solution in the $class library library is similar to what I’ve done for undefined. I created a dummy class called Null and put a special case in the $class.instanceOf and $class.getClass methods to consider the null value to be an instance of Null and nothing else.

Spam Comments

Wednesday, June 7th, 2006

I got flooded with over 50 spam comments last night ranging from random phrases that mean nothing to a short pornographic story involving a 17 year old boy and his dog. Until I get some time to work on preventing automated comment submissions, I have changed my settings to allow only registered users to post comments.

Java-like Object-Oriented Code in Javascript

Friday, June 2nd, 2006

[extremely edited - I originally had a very detailed post here about a javascript library I just released. I realized that that amount of detail deserves a more static page than a blog entry, so I moved the details out of this post (to a page created through the blog software because I’m lazy :) )]

Javascript is a very loosely-typed and dynamic language. Variables can be of any type, function parameters can be of any type, and properties of objects can be added and removed at runtime. This can be very useful in many situations, but it can also create some pretty nasty messes that are a nightmare to maintain. Sometimes more rigid structuring is needed.

There are several techniques and libraries available for creating object-oriented Javascript that support inheritance, but they usually involve some difficult-to-read syntax and fail to provide other object-oriented features like abstract methods and interfaces. My goal is to create a Javascript library that provides many of these features and eases the pain of developing complex javascript solutions. My first step towards that goal is the initial release of The $class Library (as of this posting, I’ve actually made one change since the initial version in response to the first comment).

The $class Library will be improving as I receive feedback. Check it out and tell me how it could be better (I already know the file could be smaller; I’ll work on that soon).

Javascript’s RegExp Has an Identity Crisis

Friday, June 2nd, 2006

I came across something strange while working on a javascript library for defining classes, creating inheritance relationships and testing inheritance relationships. Click the buttons and observe the output:


So is a RegExp a function or not? In the Firefox browser, typeof says yes. In all browsers, instanceof says no. Common sense says RegExp can be called like a function, so it should be considered an instance of both Function and RegExp (I would think RegExp should inherit Function). I plan on addressing this issue in my library (which still needs a catchy name so I can stop calling it “a javascript library for defining classes, creating inheritance relationships and testing inheritance relationships”).