Site Archives

JAVASCRIPT: Method overloading


John Resig, one of my heroes and creator of the jQuery JavaScript library, wrote a great piece about overloading methods. He created a dead simple function that shoulders most of the work. Check it out:

1
2
3
4
5
6
7
8
9
function addMethod(object, name, fn){
var old = object[ name ];
object[ name ] = function(){
[...]

JAVASCRIPT: Creating objects and methods


That’s right, object-oriented Javascript. Let’s get to it. We’re going to make an object for storing and retrieving user information.
Let’s start with the base object:

1
2
var User = function(firstName, lastName, emailAddress) {
}

We have to initialize the variables so that they’re available to the rest of the methods of this object:

1
2
3
4
5
var User = function(firstName, lastName, [...]

FLASH: Recursively parse XML into an array


Flash does not make it easy to handle XML. I’ve used some really bad code to help me parse arrays until I came up with this. It doesn’t handle elements of the same name at the same level, but it can probably be modified to do so.

var myParsedXML = new Array();
 
var myXML = [...]