Get the App
SLTechnology News&Howtos  ›  Development  › 

Description and example usage of javascript Combinatorial inheritance

Shulou Source: shulou.com Published: 2022-06-03 17:38:19 09月15日 Update

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!

Tags: Examples combinations prototypes properties methods content functions learning practicality deeper interest can make practical practical easy to operate more friends classics websites channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info Microsoft Apple Redmi