1.原型链继承
创建对象时会自动继承原型上的所有方法和属性,所以就是将子类的原型变成父类
2.用call继承(借用构造函数)
在子类的内部调用父类,通过call改变父类中this的指向
等于是复制父类的实例属性给子类
function myfunc1(){this.name = 'Lee';this.myTxt = function(txt){ console.log( 'i am',txt ); }}function myfunc2(){myfunc1.call(this);}
3.组合继承
4.extends(类的继承)
5.寄生式继承
1核心:封装一个函数,在内部用object.create()让obj.__proto__等于0,获得他的所有方法和实例创建一个仅用于封装继承过程的函数,该函数在内部以某种形式来做增强对象,最后返回对象。function h(o){const obj = Object.create(o);//将obj寄生在person上,获得他的属性和方法obj.sayHellow = function(){//给obj添加函数的方式增强对象,新增属性和函数增强对象console.log(this.name+this.age)}return obj;}var person = {name :'Lee',age : 18,}h(person).sayHellow()//Lee18
6.组合式寄生式继承
function Father(name,age){this.name = name,this.age = age,this.list = [1,2,3,4,5]}Father.prototype.sayhello = function(){console.log('叫'+this.name+'今年'+this.age+'岁'+this.list);}function Child(name,age) {Father.call(this,name,age);}// 2. 添加寄生式继承Object.createChild.prototype = Object.create(Father.prototype);// Child.prototype.__proto__ === Father.prototype; 产生原型的继承关系// 3. 重新制定子类原型对象的构造函数Child.prototype.constructor = Child;const child = new Child('胡入侵',199)console.log(child);child.sayhello();

