es5 简单继承
var father=function(){}; father.prototype={ constructor:father, test:function(){ console.log(1); } } var son=function(){}; son.prototype={ constructor:son, dd:function(){ console.log(23); } }; var tem=function(son){ Object.getOwnPropertyNames(son.prototype).forEach(i=>{ this[i]=son.prototype[i]; }); } tem.prototype=new father(); tem.prototype.constructor=tem; son.prototype=new tem(son); son.prototype.constructor=son; var r=new son(); console.log(r instanceof father); console.log(r instanceof son);
使用了一个tem的function 然后将子类的prototype合并到实列本身 然后 r=new tem() r就是实例对象 然后 r实例具有 son的prototype属性就在r上面了