p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 (http://p2p.wrox.com/book-professional-javascript-web-developers-isbn-978-0-7645-7908-0-174/)
-   -   book related questions here (http://p2p.wrox.com/book-professional-javascript-web-developers-isbn-978-0-7645-7908-0/37069-book-related-questions-here.html)

jminatel January 11th, 2006 10:18 AM

book related questions here
 
Don't forget, this particular forum exists mainly to discuss the book Professional JavaScript for Web Developers. Fair game includes anything that you can't understand, think doesn't work right, or even "why does it work this way" related to something specific in the book. General "how do I do this with JavaScript" questions posted here might get answered but they might not. Your best bet for non-book JavaScript "how do I" questions however is in the "JavaScript How-To" forum here at:
http://p2p.wrox.com/javascript-how-87/

Thanks for your participation.

Jim Minatel
Senior Acquisitions Editor
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Jim's Book of the week: No book this week - Donate to the Red Cross!

dharrison2010 January 30th, 2013 06:52 PM

Passing References
 
Confused...in the book page 88-89 you make reference to passing references is actually being passed by value; however, the code that is used to prove this does not make since to me. Inside the function setName(obj) you are creating a new Object reference, which in other languages would say this is a local variable and will die at the end of the function, thus not reflecting a change on the Object created outside the function. Here is a couple of examples:
HTML Code:

        var person = new Object();
       
        person.name = 'John';
       
        console.log(person.name);
       
        function changeName(obj){
                obj = new Object();
                obj.name = 'Nick';
                return obj.name;
        }
       
        console.log(changeName(person));
        console.log(person.name);

This example produces: John, Nick, John
HTML Code:

        var person = new Object();
       
        person.name = 'John Doe';
       
        console.log(person.name);
       
        function changeName(obj){
                // obj = new Object(); comment out
                obj.name = 'Nick';
                return obj.name;
        }
       
        console.log(changeName(person));
        console.log(person.name);

This example, commenting out the creation of a new Object inside the function, produces: John, Nick, Nick

Which suggest to me that it was in fact passed by reference and not by value.

Any further clarity on this would be appreciated.

Regards,

Darren


All times are GMT -4. The time now is 08:36 PM.

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