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 does JavaScript prototype chain inheritance mean?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces what JavaScript prototype chain inheritance refers to, the article is very detailed, has a certain reference value, interested friends must read it!

1. Each constructor has a prototype object that contains a pointer to the constructor, while the instance contains an internal pointer to the prototype object.

2. When the prototype object is equal to another type of instance, it inherits.

If a constructor instance object modifies property values and methods on the prototype object, it also affects other instance objects. And the property cannot be set.

Example

/ / the prototype chain inherits the properties and methods defined in function Animal () {} / /. All instance objects share Animal.prototype.name = 'xb';Animal.prototype.age = 2bot Animal.prototype.sayName = function () {console.log (this.name);} function Dog () {} Dog.prototype=new Animal;// completes a prototype chain inheritance Dog.prototype.constructor = Dog;// to reassign the constructor var D1 = new Dog () Console.log (D1); / / Dog {} console.log (d1.name); / / xbd1.sayName (); / / xb is all the content of the article "what does JavaScript prototype chain inheritance refer to". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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