<! DOCTYPE html>//Human's constructor functionPeopleclass () { This. Type = ' Person '; } //the methods that people havePeopleclass.prototype ={getType:function() {Console.log (' This is a man '); }, Getsex:function() {Console.log (' I'm a man '); } }; //Student's constructor function functionstudentclass (name, sex) {//inherit all properties of PeopleclassPeopleclass.apply ( This, arguments); //inherit all methods of Peopleclass for(varPropinchpeopleclass.prototype) {//This is pointing to the Peopleclass varProto = This. Constructor.prototype; if( !Proto[prop]) {Proto[prop]=Peopleclass.prototype[prop]; } proto[prop][' super '] =Peopleclass.prototype; } This. Name =name; This. Sex =sex; } varStu =NewStudentClass (' Zion ', ' Male '); Console.log (Stu.type); //peopleStu.gettype ();//This is a personStu.getsex ();//I'm a man.</script>
A small example of JS object-oriented inheritance properties and methods