Wrox Programmer Forums
|
BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers, 2nd Edition by Nicholas C Zakas; ISBN: 9780470227800
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2010, 12:50 PM
Authorized User
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 15 Page 524 Question

Page 524 has the following code:

function createDocument(){
if (typeof arguments.callee.activeXString != “string”){
var versions = [“MSXML2.DOMDocument.6.0”, “MSXML2.DOMDocument.3.0”,
“MSXML2.DOMDocument”];
for (var i=0,len=versions.length; i < len; i++){
try {
var xmldom = new ActiveXObject(versions[i]);
arguments.callee.activeXString = versions[i];
return xmldom;
} catch (ex){
//skip
}
}
}
return new ActiveXObject(arguments.callee.activeXString);
}

Questions:

Is activeXString a custom property on the function?
If so, as it is defined within the function, is it not destroyed once the function exits? And if that is the case then shouldn't the for loop run each time the function is called; this would make the last line of code superfluous would it not?

Thanks
 
Old September 14th, 2010, 02:49 PM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Yes, activeXString is a custom property on the function. Remember, in JavaScript functions are also objects. The function remains in memory until the page is unloaded, so you can add properties to it and retrieve their value later. So calling this function the first time causes the loop to be used in order to determine the correct ActiveX object to use. Once determined, this is cached in the function's activeXString property so all subsequent calls to the function simply return the already-identified correct string.
__________________
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about page redirection - chapter 15 janilane BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 August 30th, 2010 07:59 PM
CHAPTER 15,PAGE 533 dyla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 0 April 13th, 2010 10:58 AM
Chapter 15 Role Management Question will.wei BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 April 9th, 2009 02:17 AM
Chapter 15 FooReader.Net Question maxint40 BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 5 April 13th, 2007 09:14 AM
Chapter 15 - functions.php question buzzuh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 7th, 2004 08:31 AM





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