方式1:Son.prototype=Father.prototype
方式2:Son.prototype=new Father()
方式3:Son.prototype.__proto__=Father.prototype
方式4:Son.prototype=Object.create(Father.prototype) //Object.create()会创建一个空对象,他的__proto__指向Object.create()的第一个参数
上述几个方法均会造成Son.prototype中的constructor属性指向错误。要及时修改此属性的指向来联合使用。
子类实例要使用父类的私有方法:在子类中添加 父类.call(this); 其中this 指向子类的实例例如Function Son(){
Father.call(this); //父类执行,并把其中的this指向调用时子类的实例
this.name=name;
}