Way 2 Web

Web development tips


 
Javascript Tips

Javascript - the ugly duckling.

For years, Javascript was my pet hate. I avoided it wherever possible. Sure it was good for quick form validation and alerts, but it was a horror to work with: messy, unstructured, unwieldy, and difficult to debug.

I was not alone.

Today Javascript is my new love.

So, what has changed?

Let there be AJAX

Javascript itself has not changed; the way we use it has.

Creative programmers started doing things with Javascript no-one had dreamed possible. AJAX applications (Gmail, for instance) started to appear and reveal the graceful swan that lies within our much maligned Javascript.

AJAX, or Asynchronous Javascript and XML, is a programming style used to create web applications that offer very fast user interaction and UI updates. Instead of refreshing the entire web page for every user action, bits of XML are sent between the browser and server. DOM elements are updated dynamically.

Javascript powers all of this on the client. But not the old-style Javascript from the spagetti coding days. These applications require coding that is better thought-out and more disciplined, using object-oriented techniques and design patterns. (More on those perhaps in later articles.)

Javascript has been able to make this jump because of key qualities it has had all along:

  • It allows a form of Object-Oriented programming
  • It is implemented mostly uniformly across browsers. (We have tools to overcome the browser inconsistencies that do exist)

Firefox debuggers

Firefox has lightened the Javascript burden greatly, starting with its Javascript Console, which makes it easier to locate errors.

A number of Javascript debuggers have emerged too, as Firefox plugins.

What to expect

This section deals with some random Javascript issues and approaches.

See the Javascript Widgets section for some handy tools that demonstrate object-oriented programming in Javascript.