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

Description and example usage of javascript Combinatorial inheritance

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

Share

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

This article mainly explains "the explanation and example usage of javascript combinatorial inheritance". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the explanation and example usage of javascript composition inheritance".

Combinatorial inheritance is sometimes called pseudo-classical inheritance, which combines prototype chains and embezzlement constructors.

1. Inherit the properties and methods on the prototype through the prototype chain, and steal the constructor to inherit the instance properties.

2. This not only defines the method as a prototype, but also enables each instance to have its own properties.

Example

Function Super (name) {this.name = name this.friends = ['zs',' ls']} Super.prototype.walk = function () {console.log (this.name +'is walking.')} function Sub (name, age) {Super.call (this, name) this.age = age} Sub.prototype = new Super () Sub.prototype.run = function () {console.log (this.name +'is'+ this.age + 'years old. He can run now.')} const p1 = new Sub ('wzq', 24) p1.walk () p1.run () p1.friends.push (' zmk') console.log (p1.friends) const p2 = new Sub ('zmk', 24) p2.walk () p2.run () console.log (p2.friends) so far, I believe you have a deeper understanding of the "javascript combination inheritance instructions and examples of usage", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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