p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 (http://p2p.wrox.com/forumdisplay.php?f=174)
-   -   Resolution of property names on window object (http://p2p.wrox.com/showthread.php?t=46123)

AGS August 3rd, 2006 08:17 PM

Resolution of property names on window object
 
I have a question regarding resolution of property names on global object (window object in case of browser hosting environment).

Lets say we have a global variable with the same name as property of a window object.
Code:

var location = "Test";
Global variable is in fact a property of global object (window). So having declared global variable location we cannot access original window.location property anymore.

As far as I know there is no way to access original property of window in this case but maybe someone has a clue?

Interestingly enough it seems that in Firefox window’s property takes precedence over global variable of the same name and for example var location = "Test.html" changes current location.



nzakas August 4th, 2006 04:57 PM

You'd only be able to access it if you had saved a reference to the original before creating your own variable.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/

AGS August 4th, 2006 06:18 PM

Thanks Nicholas, that's all I wanted to know.
But what about Firefox? Does its implementation seem logical for you?


nzakas August 5th, 2006 11:50 AM

I'm not sure I'd call it "logical". It seems to go against the theory that you may want to override some previously defined variable.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/


All times are GMT -4. The time now is 05:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.