views:

55

answers:

1

I am looking at javascript file and they started it off as

var myPage = new Object();
var myDocument = document.all;

then there is some code. and then this part

myPage.Search = myDocument.Search;
myPage.Search.searchType = "Description";

I am using eclipse with aptana. I want to know why would someone wanna do this

myPage.Search = myDocument.Search;

why not

myDocument.Search.searchType = "Description";
A: 

It depends on the rest of the code. if myPage is passed into a function later, the myPage.Search = myDocument.Search; will allow the client function to access Search without having to access myDocument. The assignment to searchType can then be done either way.

The fact that they are using document.all is a good indication that you want to stay far away from that code. document.all hasn't been a sensible way to access elements since IE 4. at least use document.getElementById() -- But really, use a library like jQuery or Prototype.

Sean McMillan