When a function passes in a parameter is a reference type of several cases and phenomena.

Source: Internet
Author: User

1         functionhehe (o,oo) {2o = ' xoxo '3Oo.ins.name = ' Zhangmingzhi; '4         }5         varobj = {6 ins:{7                 8             }9         }Ten hehe (obj.ins,obj); OneConsole.log (obj);

In case 1, when the passed parameter is OO, for a reference type, the value of the parameter modification is reflected externally as obj.

Case 2, the passed parameter is O, is a reference type, the value of the parameter modification is not reflected in the external obj.ins

According to the conjecture of Scenario 2: It is possible that obj's reference address on the stack might just be storing obj and ins on the real address on the heap. If the obj.ins is passed in as a parameter, then the operation of this incoming value is not the value of the stack address, natural in the method can not be changed to reflect the Obj object outside the

PS: Above is just conjecture, go back to turn over the book.

When a function passes in a parameter is a reference type of several cases and phenomena.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.