Friday, November 03, 2006

I was changing around some javascript on one of my pages and came to a piece where I wanted to access a variable several times. I remembered using a "with" statement when doing some programming Visual Basic for Access. I looked up the with statement and found out that it is not recommended to use.


alert(document.title);
alert(document.body.tagName);
alert(document.location);


Here is the with Statement:


with (document) {
alert(title);
alert(body.tagname);
alert(location);
}



"It is another scope. When you use the with statement, you are forcing the interpreter to not only look up the scope tree for local variables, but you are also forcing it to test each variable against the object specified to see if it's a property" - "Professional Javascript for Web Developers, Nicholas C Zakas, p 581