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";
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.