A New-Found Respect for Javascript

by Charles Miller on February 10, 2003

For a long time, I've considered Javascript to lie somewhere beneath my contempt as a language. Which is a pity, because it's not really Javascript's fault. Browsers' support of the language has always been underwhelming, and grossly incompatible. in the past, whenever I've tried to do anything with Javascript it's taken far too much time, and because the capabilities just weren't there, it never never quite worked the way I wanted it to.

Javascript itself is a small language, but that wasn't the problem. The problem was that what we generally refer to as being ‘Javascript’ is really the intersection of the language itself, plus the DOM (and to some extent CSS) support of whatever browser it's being run in. And it's only in the last year or so that web browsers have had anything approaching decent DOM/CSS support.

Secondly, the annoyance factor of so many people not being able to tell Java and Javascript apart (curse you, Netscape marketing weenies!) made me prejudiced against the language whenever it was mentioned.

In the last few days, I've finally had the chance to get down with my two-inch thick O'Reilly DHTML book, and write a useful scripted page for the project I'm working on. Here's what I learned.

  • Javascript's object model is simple, very flexible, and pleasant to use.
  • I really liked having first-class functions and closures. I found myself writing things like ["id1", "id2", "id3"].map(function(item) { return document.getElementById(item); });. A cow orker looked at what I'd written and accused me of being too Smalltalky (and I've never coded Smalltalk seriously)
  • DOM support in version 6 browsers is very good. Manipulating a webpage is surprisingly easy. (Although my point of reference here is the Version 4 browser, when I last attempted this sort of thing)
  • That DHTML book is incredibly good, and no web developer should be without it.
  • This sort of thing is only really practical if you forget that browsers older than Mozilla or IE6 exist.
  • While I had the luxury of targeting my code at a single browser version, everything I did could easily be made cross-browser in half an hour (taking into account the previous definition of “cross-browser”.
  • Being a closet HTML nerd (and thus knowing where to look for things in the HTML DOM, and what CSS to manipulate to make things move around or disappear) helps.
  • Most importantly, spending two days learning a language I've never really programmed in before, in order to fulfil a valuable goal, is a good experience. I really should go back to improving my Ruby skills, too.

Previously: A foolish consistency

Next: Moving, maybe...