XMLHttpRequest Object W3C Working Draft

I found this article over at Ajaxian. W3C has taken notice of the use of the XMLHttpRequest and has decided to standardize it! w00t! W3C says:

The XMLHttpRequest object is implemented today, in some form, by many popular Web browsers. Unfortunately the implementations are not completely interoperable. The goal of this specification is to document a minimum set of interoperable features based on existing implementations, allowing Web developers to use these features without platform-specific code. In order to do this, only features that are already implemented are considered. In the case where there is a feature with no interoperable implementations, the authors have specified what they believe to be the most correct behavior.

This is pretty exciting because we can now see a proposed consistent method for using the object will be solidified in future browsers! Now…lets hope the browsers implement it quickly :) Oh, and here’s an example of setting a Request Header:

// The following script:
var r = new XMLHttpRequest();
r.open('get', 'demo.cgi');
r.setRequestHeader('X-Test', 'one');
r.setRequestHeader('X-Test', 'two');
r.send(null);

// ...would result in the following header being sent:
...
X-Test: one, two
...

Object Oriented JavaScript

javascript.gifJavascript has invaded my life. And I like it.

I have developed web applications for quite some time, writing Javascript off an often unnecessary tool that simply added frills. Over the course of this year – with the birth of the Ajax hype – I realize my error. I began inserting javascript all over hell’s half acre and raving about its sweetness. I’ve grown in a year.

As I develop more javascript-rich web applications for my amusement and my job, I am constantly seeking better ways to structure both data and code. It wasn’t until a month ago that I really began to dig into the Prototype and Script.aculo.us code (rather than simply using it) and began to grow aware of what was actually going on. Object Oriented Javascript.

I think it is important to note (so I don’t look like a complete nitwit) that I was aware that Javascript had this capability a couple of months back before I picked up and started using the afore mentioned Javascript libraries…I just had no drive to learn it and spot where it was being used. I have seen the light and it is good.

What are its benefits? Well, pretty much the same applies to Javascript that applies to any other programming language…OOP helps increase organization and reduce un-needed redundancy. And best of all? It helps prevent dual-declared functions and variables. That is the reason I chose to begin my quest for OO-JS familiarity.

I had gone hunting at a few other sites that claimed to be good references (obviously) of OO-JS, but they lacked the topic of inheritance, which is the real strength of any OOP Language. The most helpful article I found on the topic was at WebReference. They discuss the use of prototype (Not the Javascript Library). Here’s a quick excerpt, but I’d suggest you read the article for yourself!

Excerpt from WebReference

function Person() {
      this.name = "Rob Roberson";
      this.age = 31;
}

function Employee() {
      this.dept = "HR";
      this.manager = "John Johnson";
}

Employee.prototype = new Person();

var Ken = new Employee();

Ken is in the prototype chain of Employee, Person, and Object.

Check it out. Use it. You’ll like it. You’re applications will like it. Oh, and it may prove useful to check out some Javascript Coding Conventions.