function person(name,age){this.name=name;this.age=age}; person.prototype={say:function(){console.log('hello')}};
function student(){};
student.prototype=Object.create(person.prototype) ; // Object.create(person.prototype) 创建一个空对象,空对象的原型指向person.prototype;
var xiaoming=new student();
student.prototype.study=function(){console.log("chinese")};
xiaoming.say(); xiaoming.study();
student.prototype=new person("xiaohong",30); // 如果用new出一个实例,可能不是空对象了,student.prototype那么赋值得到就是个带属性和方法的对象,原型当然还是指向person.prototype;
var xiaoming=new student();
student.prototype.study=function(){console.log("chinese")};
console.log(xiaoming.age); console.log(xiaoming.name);