function Man(name,age){
this.name=name;
this.age=age;
}
var person=new Man(‘judy‘,18)
function Woman(name,age){
this.sex=‘woman‘
Man.call(this,name,age)
}
Woman.prototype=Man.prototype;
var person1=new Woman(‘lisa‘,20)
console.log(person1.name,person1.age,person1.sex)//结果为lisa 20 woman;
原型链查找:进行方法调用的时候,会先在实例自身上找,如果没有就去该实例原型上找;
function People(){
this.name=‘a people‘;
}
People.prototype.say=function(){
this.age=‘10‘
console.log(this.name,this.age)
}
var person=new People();
console.log(person.say())//输出结果为 a people 10