Description and example usage of javascript Combinatorial inheritance
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!