I’ve been working a lot with Javascript lately for projects at work, mainly due to the AJAX-enabled components of one of our latest products.

I’ve generally avoided Javascript over the last year or so, whenever I wrote basic functions, they always seemed bloated and very specific to a task or scenario. Plus, javascript has got a pretty bad name over the last ten years, let’s be honest. It’s been used to do some downright horrible things.

I guess in the early days of new technology, we tend to concentrate of what can be done that’s “cool” rather than what can be done that’s useful for the user. Maybe we’re seeing the same thing with AJAX right now, but I guess that’s all part of a technologies life cycle and difficult to avoid.

So anyway, the big change in my feelings towards Javascript has been the Document Object Model. The DOM has changed everything. Well, not so much just the DOM, but more so that almost all browsers now support a standard W3C DOM architecture.

This standard DOM has gone a long way to improving reusability of code. For example, I wrote a basic javascript validator not so long ago that will validate a form with any number or type of input elements. The only variable that needs to be passed to the function was the form node, the script would then just iterate through each child node and run the validation test. In the past, you may have had to pass the ID of each input element that you wanted to validate, making the script somewhat cumbersome. By relying on the DOM for the validator, it made the script essentially drag-and-drop like.

There is also the move to writing object oriented Javascript. Many of the libraries released in the last year like Prototype and Scriptaculous are written in an object oriented fashion. This means that the scripts are easily extendable and are designed in a way that is well thought out and logical. It may also make many other established programmers who once ‘poo-pooed’ Javascript sit up and take note.

I’m going to be studying the DOM and object oriented Javascript a lot more over the coming months as I think there is real potential in this area for UI developers.

Technorati Tags: