The following editor will bring you an OOP inheritance implementation of js (a must-read article). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
The reason why Student.prototype is created using the create method instead of directly assigning the value of Person.prototype is because if assignment is used If so, both point to the same object. If we want to add a new method to the student class, that won't work. So if you use the create method to use Person.prototype as the prototype of Student.prototype
If we modify the attributes on bosn's prototype, then bosn will be affected . It should be noted that we found that if the prototype object of bosn is modified, bosn will not change. For an instance that has already been created, modifying the prototype object will not cause the instance to change.
The above OOP inheritance implementation of js (a must-read article) is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more related articles on OOP inheritance implementation of js (must-read article), please pay attention to the PHP Chinese website!