原型继承
<script>
/*****原型继承*****/
// 构造函数
function Person(){
this.uname = '张三'
}
// Person的实例化对象
let p1 = new Person()
// 构造函数
function Student(){}
// 原型继承
Student.prototype = p1
// 实例化Student
let s1 = new Student()
console.log(s1.uname); //张三
</script>
构造函数继承
<script>
/******构造函数继承******/
// 构造函数
function Person(){
this.uname = '张三'
}
Person.prototype.say =function(){
console.log('我是张三');
}
// 构造函数
function Student(){
Person.call(this)
}
let s1 = new Student()
s1.say() //s1.say is not a function
</script>