1 functionCreateperson (name,sex) {2 This. name=name;3 This. sex=sex;4 This. ShowName ();5 This. Showsex ();6 }7Createperson.prototype={8Constructor:createperson,//Fix Constructor9ShowName:function(){TenAlert This. Name); One }, AShowsex:function(){ -Alert This. Sex); - } the } - NewCreateperson (' Xiao Ming ', ' Male ')); - - functionCreatestar (name,sex,job) { +Createperson.call ( This, name,sex);//Inherit Createperson Property - This. job=job; + This. Showjob (); A } at -Copyobj (Createstar.prototype,createperson.prototype);//copy all methods that inherit Createperson.prototype - -createstar.prototype.showjob=function(){ -Alert This. Job); - in } - NewCreatestar (' Huang Xiaoming ', ' Male ', ' actor '); to + //Copy all the methods of the parent class to the child class - functionCopyobj (newobj,oldobj) { the for(attrincholdobj) { *newobj[attr]=oldobj[attr]; $ }Panax Notoginseng}
Property inheritance and method inheritance of OOP