About js inheritance method, solve!

  node.js, question
function person(name,age){
 this.name = name;
 this.age = age;
 bracket
 person.prototype.say = function(){
 Console.log(this.name plus ":"plus this.age);
 bracket
 
 function superman(name,age){
 person.call(this,name,age);
 bracket
 superman.prototype = new person();
 
 var s = new superman('superman',29);

I read in the book that this way of inheritance is perfect, but I don’t think so, because of hissuperman.prototype = new person();This sentence will add the instance attribute of the parent class to the prototype of the subclass, althoughperson.call(this,name,age);I have already got the instance attribute of the parent class, but I feel this pollutes the prototype of the child class, What’s to be done?

Well, the problem has been solved, using parasitic combinatorial inheritance can solve this problem.

function object(obj){
 function F(){}
 F.prototype = obj;
 return new F();
 bracket
 
 function inheritProtoType(SuperType,SubType){
 var prototype = object(SuperType.prototype);
 prototype.constructor = SubType;
 SubType.prototype = prototype;
 bracket
 
 function SuperType(){
 this.name = 'yuhualingfeng';
 this.friends = ['David','Bob','Lucy'];
 bracket
 SuperType.prototype.saySuperName = function(){
 console.log(this.name);
 };
 
 function SubType(){
 SuperType.call(this);
 this.age = 30;
 bracket
 inheritProtoType(SuperType,SubType);
 
 SubType.prototype.saySubName = function(){
 console.log(this.name);
 };
 
 var subType = new SubType();

Object.create(Person.prototype);

This can be effectively solved, but attention should be paid to compatibility.

function create(obj) {
 if (Object.create) {
 return Object.create(obj);
 bracket
 
 function f() {};
 f.prototype = obj;
 return new f();
 bracket