<script>
// 1,原型继承 语法: 子类构造函数.prototype=父类的实例化对象
// 缺点: 参数不只是写在子类构造函数里面 而且继承来的属性没有在自己身上 而是在自己的__proto__上面 继承之前子类有的原型上面的方法会被覆盖掉
function Person(name){
this.name = name;
}
Person.prototype.sayHello=function(){
console.log('hello');
}
var p1 = new Person('dog');
console.log(p1);
p1.sayHello();
function Student(age){
this.age = age;
}
// Student.prototype.sayHi=function(){
// console.log("hi"); 继承之后这个方法会被覆盖掉 这里就注释了
// }
// 开始继承
Student.prototype = new Person('lili'); // 继承完成 继承会清除子类构造函数之前的原型方法;
var s1 = new Student(12);
console.log(s1);
console.log(s1.name);
s1.sayHello();
// s1.sayHi();
</script>