05 Jun 2006

prototype.js is the web developer's internet explorer

i'll let that sink in for a minute. prototype.js is probably the most popular ajax javascript library on the net in 2005-2006. it does some evil things that many people have blogged about endlessly.

the problem is that it aggressively extends the base javascript Object and the Array object adding around 10 or so functions that allow it to behave as an iterator and allow subclassing. those additions are nice to have, but it means it does not play well with any other javascript libraries unless they explicitly work within the new walls it puts up. the walls it puts up refers to the fact you cannot use associative arrays nicely like this as it will print out the extra prototype.js methods:

var anArray = {1: "a", 2: "b", 3:"c"};
for (var aKey in anArray) {
i personally prefer MochiKit's unobtrusive behaviour which makes it much better to use when you're gluing different javascript libraries together.

just like how you cannot avoid considering internet explorer when designing a web page, same goes with having to consider prototype.js when doing anything with javascript. probably the most often complained about bug with plotkit is that it does not work with prototype.js.

i've started to work around this broken behaviour by making my own wrappers around MochiKit's functional programming constructs like "map" to check for prototype.js' meddling and add an extra check to strip out all the functions it adds. it's an ugly stopgap measure, but at least it will make plotkit work with prototype.js, albeit unwillingly. it's the best compromise i can think of to keep the readability of the code. here's to hope that people will see the light and stop using prototype.js unless they want to live in their walled garden. although i doubt it will happen because so much is invested in that javascript library. really cool things like scriptaculous, lightbox and rubyonrails all depend on it, so it's not going away in the near future.

prototype.js 1.5 is rumoured to remove Array.prototype poisoning, but i suspect existing libraries will take their time migrating to this new version. hence the parallel between ie6 and ie7 with prototype.js 1.4.x and prototype 1.5 respectively. things may get fixed in the future versions, but it's still broken and too popular at the moment to ignore.

You can reply to me about this on Twitter: