Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the points for attention of JavaScript prototype chain inheritance

Shulou Source: shulou.com Published: 2022-06-03 10:44:38 11月15日 Update

Editor to share with you what are the points for attention of JavaScript prototype chain inheritance, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Reference attribute problem, add reference value attribute to the prototype object, although we usually put the property in the constructor, it will appear in the prototype inheritance.

2. A subclass cannot pass parameters to the constructor of the parent class when instantiating.

Example

Function A () {this.arrs=; function B () {} B.prototype = new A (); let C1 = new B (); let c2 = new B (); console.log (c1.arrs); / / [1m 2m 3] console.log (c2.arrs); / / [1m 2m 3] c1.arrs.push (4); console.log (c1.arrs); / / [1m 2m 3J 4] console.log (c2.arrs) / / [1, 2, 3, 4] the above are all the contents of the article "what are the points for attention in the inheritance of JavaScript prototype chain". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Prototypes properties articles content functions examples not much most subclasses objects regular meetings more knowledge industry information information channels questions channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Linux OPPO Reno Redmi