In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to transmit parameters for javascript complex types. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Description
1. In the process of passing the argument to the parameter, the complex data type is passed to the parameter's address rather than the object instance.
2. The formal parameter of the function can also be regarded as a variable.
When we pass a variable of a reference type to a parameter, we actually copy the heap address where the variable is stored in the stack space to the parameter. Formal parameters and arguments are actually stored in the same heap address, so you are operating on the same object.
Example
Function Person (name) {this.name = name;} function fun1 (x) {/ / 8. Since the formal parameter x points to the address p, the output is still the object instance {new Person ('Andy Lau'); name = 'Andy Lau'} / / 9. The second output: 'Andy Lau' console.log (x.name); / / 10. X.name is re-assigned, and the object instance is changed to {new Person ('Liu Dehua'); name = 'Jacky Cheung'} x.name = 'Jacky Cheung'; / / 11. The third output: 'Jacky Cheung' console.log ('2' + x.name);} / / 1. Define a complex data type / / 2. The complex data type variable p stores the address p in the stack, and the variable p points to the address p / 3. The real object instance {new Person ('Andy Lau'); name = 'Andy Lau'} is stored in the heap / / 4. The variable p points to the address p in the stack, and the address p points to the object instance in the heap {new Person ('Andy Lau'); name = 'Andy Lau'} var p = new Person ('Andy Lau'); / / 5. The first output: Andy Lau console.log (p.name); / / 6. Pass the variable p to parameter x, that is, the address p to parameter x / / 7. Then both the variable p and the parameter x point to the same address, the address p fun1 (p); / / 12. In this case, the object instance of p.name is {new Person ('Andy Lau'); name = 'Jacky Cheung'} / / 13. The fourth output: 'Zhang Xueyou' console.log (p.name); this is the end of this article on "how to transmit parameters of javascript complex types". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.