Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the disadvantages of js reference type values

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the shortcomings of js citation type values. 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.

1. If a reference type value is defined in a type, then all inherited shared reference type values.

Inheritance of value types does not result in sharing, and memory space is allocated separately.

/ / parent constructor function Father () {this.name = "father"} / / Child constructor function Children () {} / / implement inheritance: prototype object of child constructor = instance object of parent constructor Children.prototype = new Father () / / create child instance let C1 = new Children () let c2 = new Children () / / No problem with referencing type value c1.name = "I fix it" Changed name "console.log (c1.name) / / I modified name console.log (c2.name) / / father

2. Inheritance of reference types can lead to shared and shared memory space. After the reference type inherits, all instances share a share of data.

/ / parent constructor function Father () {this.child = {name: 'father'}} / / Child constructor function Children () {} / / implement inheritance: prototype object of child constructor = instance object of parent constructor Children.prototype = new Father () / / create child instance let C1 = new Children () let c2 = new Children () / is the reference type value If there is a problem, c1.child.name = "I modified name" console.log (c1.child) / / {name:'I modified name'} console.log (c2.child) / / {name:'I modified name'} about what are the shortcomings of js reference type values. This article ends here. Hope that the above content can be helpful 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report