Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 14th, 2010, 12:50 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
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
  #2 (permalink)  
Old September 14th, 2010, 02:49 PM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
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/
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 07:20 PM.


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