Use a graph to represent the new prototype chain:
Encapsulates a inherits () function, function F for bridging
function inherits (Child, Parent) { varfunction () {}; = Parent.prototype; New F (); = Child ;}
This allows the inherits () function to be reused.
functionStudent (props) { This. Name = Props.name | | ' Unnamed ';} Student.prototype.hello=function() {alert (' Hello, ' + This. Name + '! ');}functionprimarystudent (props) {Student.call ( This, props); This. grade = Props.grade | | 1;}//To implement a prototype inheritance chain:inherits (Primarystudent, Student);//to bind other methods to the Primarystudent prototype:PrimaryStudent.prototype.getGrade =function () { return This. grade;};//Create Xiaoming:varXiaoming =Newprimarystudent ({name:' Xiao Ming ', Grade:2}); xiaoming.name; //' Xiao Ming 'Xiaoming.grade;//2//Validating prototypes:xiaoming.__proto__ = = = Primarystudent.prototype;//truexiaoming.__proto__.__proto__ = = = Student.prototype;//true//To validate an inheritance relationship:XiaominginstanceofPrimarystudent;//trueXiaominginstanceofStudent;//true
Prototype Inheritance-Liaoche's official website (selected from @ Liaoche)
Https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/ 0014344997013405abfb7f0e1904a04ba6898a384b1e925000
JavaScript prototype inheritance