The implementation method of embezzling Constructor by js
This article mainly explains "the implementation of js embezzlement constructor". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "js embezzlement constructor implementation method" it!
1. The parent class constructor is called in the constructor of the subclass.
2. Because a function is just a simple object that executes code in a particular context, you can use the apply () and call () methods to execute the constructor, which takes the newly created object as the context.
Example
Function Super (name) {this.name = name} function Sub (name, age) {/ / inherits Super Super.call (this, name) this.age = age} const p = new Sub ('wzq', 24) console.log (p) so far, I believe you have a deeper understanding of "js embezzlement constructor implementation", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!